版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
JUnit
軟體測試架構(gòu)
JUnitSoftwareTestingFramework葉秉哲2002/7/4./present/20020704JUnit
的定位JUnitis…JUnitisnot…scope單元測試整合測試testware骨幹、架構(gòu)完整系統(tǒng)level工具方法論testcase手動產(chǎn)生自動產(chǎn)生testdriver/script部份手寫全自動2大綱引子JUnit
基礎(chǔ)篇JUnit
進(jìn)階篇軟體測試基礎(chǔ)推薦讀物3一、引子一流的科學(xué)家可以做出很有價值的實驗,產(chǎn)生新知識;二流科學(xué)家只是忙於各種實驗,蒐集大量數(shù)據(jù),但對知識的累積沒什麼用處。
---DavidSalsburgJUnit
簡介RegressiontestingframeworkwrittenbyErichGammaandKentBeckOpenSourceHostedonSourceForgeLanguagesupportSmalltalk,Java,C++,Perl,Python,etc.IDESupportJBuilder,VisualAge,etc.5WhatisSoftwareTesting?Theexecutionofcodeusingcombinationsofinputandstateselectedtorevealbugs.Theprocessofdevisingandexecutingatestsuitethatattemptstocausefailures,increasingourconfidencethatfailuresareunlikely.6WhyTesting?目的:矛與盾Revealbugs:qualitycontrolConfidence:qualitative&quantitative重要性Paradigm↑
productivity↑
testing&debugging↑Softwarefeaturesthatcan’tbedemonstratedbyautomatedtestssimplydon’texist.[Beck1999,p.45]7Testing:
CMMPerspectiveTheKeyProcessAreasbyMaturityLevelSource:CapabilityMaturityModelforSoftware,v1.1
/publications/documents/93.reports/93.tr.024.html8Testing:RUPPerspectiveSource:PhilippeKruchten,TheRationalUnifiedProcess:AnIntroduction,p.62,AddisonWesley,1998.9Testing:XPPerspectiveIfyou’renotvalidatingeverythingallthetime,
you’renotdoingXP.Period.Source:KentBeck,ExtremeProgrammingExplained:EmbraceChange,p.70,AddisonWesley,1999.10TestWhat?Everyartifactduringthewholedevelopmentprocessshouldbetested.11軟體測試工具分類分類實例reviews&inspectionslintCompuware
DevPartnertestplanningRationalSuiteTestStudiotestdesign&developmenttestexecution&evaluationcapture/playbackcoverageanalysisCompuware
DevPartnerRationalSuiteTestStudioBorlandOptimizeitmemorytestingCompuware
DevPartnerRationalSuiteTestStudiotestcasemanagementsumulations&performanceprofilertestsupport12JUnit
的定位JUnitis…JUnitisnot…scope單元測試整合測試testware骨幹、架構(gòu)完整系統(tǒng)level工具方法論testcase手動產(chǎn)生自動產(chǎn)生testdriver/script部份手寫全自動13JUnitFramework14junitHowtoTestwithJUnit?FooTestCaseexercise1..*TestRunnerrun1..*FooTesttest1test2…15Questions…如何測試? strategy多少測試才夠? coverage流程? process工具影響?
mediumismessage16二、JUnit
基礎(chǔ)篇ExtremeProgrammerstesteverythingthatcouldpossiblybreak,usingautomatedteststhatmustrunperfectlyallthetime. ---ExtremeProgrammingInstalledDesignGoalsofJUnitEasytouseRequiresnomoreworkthanabsolutelynecessarytowriteanewtestLeveragesexistingteststocreatenewonesReusablefixturestorundifferenttestsRetainsvaluesoftestsovertimeCombinestestsfromvariousauthorsandrunthemtogetherwithoutfearofinterference18CaseStudy自動產(chǎn)生測試框架UsingBorlandJBuilder6.0最簡單的完整測試實例19實例一FoojunitTestCaseexercise1..*FooTesttest1test2…20實例一:簡單的待測物publicclassMoney{privateintfAmount;privateStringfCurrency;publicMoney(intamount,Stringcurrency){
fAmount=amount;
fCurrency=currency;}publicMoneyadd(Moneym){returnnewMoney(amount()+m.amount(),currency());}publicint
amount() {returnfAmount;}publicStringcurrency() {returnfCurrency;}}21實例一:產(chǎn)生測試框架
[1/7]BorlandJBuilder6.022實例一:產(chǎn)生測試框架
[2/7]BorlandJBuilder6.023實例一:產(chǎn)生測試框架
[3/7]BorlandJBuilder6.024實例一:產(chǎn)生測試框架
[4/7]BorlandJBuilder6.025實例一:產(chǎn)生測試框架
[5/7]BorlandJBuilder6.026實例一:產(chǎn)生測試框架
[6/7]BorlandJBuilder6.027實例一:產(chǎn)生測試框架 [7/7]importjunit.framework.*;publicclassMoneyTestextendsTestCase{publicMoneyTest
(Strings) {super(s);}protectedvoidsetUp() {}protectedvoidtearDown() {}publicvoidtestAdd(){
intval1=0; Stringval2="STRING0"; Moneymoney=newMoney(val1,val2); Moneyval1=null/**@todofillinnon-nullvalue*/; MoneymoneyRet=money.add(val1);
/**@todo:Inserttestcodehere. UseassertEquals(),forexample.*/ }}28LessonLearnedCodealittle,testalittle29junit實例二FooTestCaseexercise1..*TestRunnerrunFooTesttest1test2…30實例二:待測物,修正版publicclassMoneyimplementsCloneable{privateintfAmount;privateStringfCurrency;publicMoney(intamount,Stringcurrency){/*...*/}publicMoneyadd(Moneym){if(m==null)return(Money)clone();returnnewMoney(amount()+m.amount(),currency());}publicObjectclone() {/*...*/}publicboolean
equals(Objectobj) {/*...*/}publicint
amount() {/*...*/}publicStringcurrency() {/*...*/}}31實例二:測試碼
[1/2]importjunit.framework.*;publicclassMoneyTestextendsTestCase{ publicMoneyTest
(Strings){super(s);} publicvoidtestNullAdd
(){ Stringcurr="NTD";
intval1=2002;
Moneymoney1=newMoney(val1,curr); Moneymoney2=null;//nullvalue Moneymoney3=money1.add(money2); Assert.assertEquals(money1,money3); }32實例二:測試碼
[2/2]
publicvoidtestSimpleAdd(){Stringcurr="NTD";
intval1=2002;
intval2=345;
intval3=val1+val2; Moneymoney1=newMoney(val1,curr); Moneymoney2=newMoney(val2,curr); Moneymoney3=money1.add(money2);
assertEquals(money3,newMoney(val3,curr)); }}33java-cplib\junit.jar;.junit.swingui.TestRunner
MoneyTestSuccess34Failure 1/235Failure 2/236Error 1/237Error 2/238LessonsLearnedGenerate&exercisetestcase(s)Writetest…()method(s)VerifyChooseaAssert.assert…()ChooseaTestRunnerjunit.textui.TestRunnerjunit.swingui.TestRunnerFailurevs.error39三、JUnit
進(jìn)階篇TheteststhatyouwriteinXPareisolatedandautomatic. ---ExtremeProgrammingExplainedCaseStudyFixture/context管理Testsuite與進(jìn)入點GroupingbytasksConfigurationmanagementRegressiontesting41junit實例三FooTestCaseexercise1..*TestRunnerrun1..*FooTesttest1test2…setUp()
tearDown()42實例三:測試碼
[1/2]importjunit.framework.*;publicclassMoneyTestextendsTestCase{privateMoneymoney1,money2,money3;publicMoneyTest(Strings) {/*...*/}protectedvoidsetUp(){Stringcurr="NTD";
intval1=2002;
intval2=345;money1=newMoney(val1,curr);money2=newMoney(val2,curr);money3=newMoney(val1+val2,curr);}
43實例三:測試碼
[2/2]
protectedvoidtearDown() {}publicvoidtestNullAdd(){ Moneymoney10=money1.add(null);//nullvalue assertEquals(money1,money10); }publicvoidtestSimpleAdd(){ Moneymoney10=money1.add(money2); assertEquals(money3,money10); }}44LessonsLearnedFixtureOverrides
setUp()Overrides
tearDown()Eachtest…()methodisisolated45junit實例四FooTestCaseexercise1..*TestRunnerrun1..*FooTesttest1test2…testcaseTestSuitetestsuite46實例四:測試碼
[1/3]importjunit.framework.*;publicclassMoneyTestextendsTestCase{privateMoneymoney1,money2,money3;publicMoneyTest
(Strings) {/*...*/}protectedvoidsetUp() {/*...*/}publicvoidtestNullAdd() {/*...*/}publicvoidtestSimpleAdd() {/*...*/}47實例四:測試碼
[2/3]
//[interactivemode] //entrypointofthewholetestsuite!/* //Version1 publicstaticTestsuite(){
TestSuitesuite=newTestSuite(); suite.addTest(newMoneyTest("testNullAdd")); suite.addTest(newMoneyTest("testSimpleAdd")); returnsuite; }*/ //Version2 publicstaticTestsuite(){ returnnewTestSuite(MoneyTest.class); }48實例四:測試碼
[3/3]
//[batchmode] //entrypointofthewholetestsuite! publicstaticvoidmain(Stringargs[]){
junit.textui.TestRunner.run(suite()); }}49LessonsLearnedTestcasesuiteWriteasuite()astheinteractivemodeentrypointWriteamain()asthebatchmodeentrypoint50實例五:CompositePattern51實例五:beforegroupingFootestsuiteexerciseFooTesttest1test2test3…
testcase52實例五:groupingbytasksFooexerciseFooTestbasictesttest1test2testsuiterandomtesttest3monkeyteststresstest53實例五:compositetestsuitespublicclassMoney_testextendsTestCase{ publicMoneyTest
(Strings){/*...*/} publicstaticTestsuite(){
TestSuitesuite=newTestSuite(); suite.addTest(Money_test_basic.suite()); suite.addTest(Money_test_random.suite()); suite.addTest(Money_test_monkey.suite()); returnsuite; } publicstaticvoidmain(Stringargs[]){
junit.textui.TestRunner.run(suite()); }}5455LessonsLearnedGroupingbyconfigurationpolicyBytasksBypersonsByrevisionsConfigurationmanagementNamingschemeProcessScripts56小結(jié):JUnit
使用四部曲FixtureOverrides
setUp()and/ortearDown()ExerciseWritestest…()VerifyUsesAssert.assert…()SuitemanagementWritessuite()and/ormain()57其他主題ReportsTestResultExtensionsforvariousapplicationdomains58四、軟體測試基礎(chǔ)Programtestingcanbeusedtoshowthepresenceofdefects,butnevertheirabsence! ---EdwardDijkstraWhyVerification/TestingisHard?理論限制IntractableUndecidable實務(wù)限制成本流程人因60軟體測試方法論:分類ScopeUnittestIntegrationtestSystemtestAcceptancetestStrategyResponsibility-based(blackbox)Implementation-based(whitebox)Hybrid(graybox)Fault-based61OOTestingManifesto觀察NosilverbulletEveryadvancehasapriceIterative&incrementalRegressiontesting信條FaultmodelsTestautomationTest-effectiveprocess62FaultModels重要性exhausivetesting不可能,合理的testingstrategy必須根據(jù)faultmodels的引導(dǎo)正面:conformance
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 資產(chǎn)評估學(xué)教程-練習(xí)答案6
- 上海市市轄區(qū)(2024年-2025年小學(xué)五年級語文)人教版開學(xué)考試(下學(xué)期)試卷及答案
- 2023-2024學(xué)年廣東省深圳市南山區(qū)七年級(上)期末英語試卷
- 三年級數(shù)學(xué)計算題專項練習(xí)及答案
- 二年級語文上冊第一單元教案
- HDPE波紋管技術(shù)規(guī)格書
- 《電氣控制系統(tǒng)設(shè)計與裝調(diào)》教案 項目三任務(wù)二:認(rèn)識熔斷器、熱繼電器
- 北京市北京匯文中學(xué)教育集團(tuán)2024-2025學(xué)年高一上學(xué)期期中考試數(shù)學(xué)試題(含答案)
- 心電探頭市場發(fā)展預(yù)測和趨勢分析
- 指甲油筆產(chǎn)業(yè)運行及前景預(yù)測報告
- 柴油采購?fù)稑?biāo)方案(技術(shù)標(biāo))
- 3.8做改革創(chuàng)新生力軍
- 掛籃檢查驗收記錄表
- 快遞員國家職業(yè)技能標(biāo)準(zhǔn)2019年版
- 作業(yè)設(shè)計-第六單元生物的多樣性及其保護(hù)
- InfoQ:2023中國企業(yè)數(shù)字化人才發(fā)展白皮書
- 鼻腔腫物的護(hù)理課件
- 2023儲能電站火災(zāi)預(yù)警及防護(hù)技術(shù)護(hù)航儲能安全
- 社區(qū)的治安狀況調(diào)查報告
- 詐騙控告書模板
- 《多邊形的面積》單元整體教學(xué)設(shè)計(課件)五年級上冊數(shù)學(xué)人教版
評論
0/150
提交評論