版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
JUnit介紹TestingframeworkwrittenbyErichGammaandKentBeckOpenSourceHostedonSourceForgeLanguagesupportSmalltalk,Java,C++,Perl,Python,etc.IDESupportJBuilder,VisualAge,etc.1/47WhatisSoftwareTesting?Theexecutionofcodeusingcombinationsofinputandstateselectedtorevealbugs.Theprocessofdevisingandexecutingatestsuitethatattemptstocausefailures,increasingourconfidencethatfailuresareunlikely.2/47軟件測試工具分類分類實例reviews&inspectionsCompuwareDevPartnertestplanningRationalSuiteTestStudiotestdesign&developmenttestexecution&evaluationcapture/playbackcoverageanalysisCompuwareDevPartnerRationalSuiteTestStudioBorlandOptimizeitmemorytestingCompuwareDevPartnerRationalSuiteTestStudiotestcasemanagementsumulations&performanceprofilertestsupport3/47JUnit定位JUnitis…JUnitisnot…scope單元測試綜合測試,組合測試testware模塊完整系統(tǒng)level工具方法輪testcase手動產(chǎn)生自動產(chǎn)生testdriver/script部份手寫全自動4/47JUnitFramework5/47junitHowtoTestwithJUnit?FooTestCaseexercise1..*TestRunnerrun1..*FooTesttest1test2…6/47Questions…怎樣測試? strategy多少測試才夠? coverage流程? process工具影響? mediumismessage7/47DesignGoalsofJUnitEasytouseRequiresnomoreworkthanabsolutelynecessarytowriteanewtestLeveragesexistingteststocreatenewonesReusablefixturestorundifferenttestsRetainsvaluesoftestsovertimeCombinestestsfromvariousauthorsandrunthemtogetherwithoutfearofinterference8/47CaseStudy自動產(chǎn)生測試框架UsingBorlandJBuilder6.0最簡單測試實例9/47實例一FoojunitTestCaseexercise1..*FooTesttest1test2…10/47實例一:簡單待測程序publicclassMoney{privateintfAmount;privateStringfCurrency;publicMoney(intamount,Stringcurrency){fAmount=amount;fCurrency=currency;}publicMoneyadd(Moneym){returnnewMoney(amount()+m.amount(),currency());}publicintamount() {returnfAmount;}publicStringcurrency() {returnfCurrency;}}11/47實例一:產(chǎn)生測試框架 [1/7]BorlandJBuilder6.012/47實例一:產(chǎn)生測試框架 [2/7]BorlandJBuilder6.013/47實例一:產(chǎn)生測試框架 [3/7]BorlandJBuilder6.014/47實例一:產(chǎn)生測試框架 [4/7]BorlandJBuilder6.015/47實例一:產(chǎn)生測試框架 [5/7]BorlandJBuilder6.016/47實例一:產(chǎn)生測試框架 [6/7]BorlandJBuilder6.017/47實例一:產(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.*/ }}18/47LessonLearnedCodealittle,testalittle19/47junit實例二FooTestCaseexercise1..*TestRunnerrunFooTesttest1test2…20/47實例二:測試碼publicclassMoneyimplementsCloneable{privateintfAmount;privateStringfCurrency;publicMoney(intamount,Stringcurrency){/*...*/}publicMoneyadd(Moneym){if(m==null)return(Money)clone();returnnewMoney(amount()+m.amount(),currency());}publicObjectclone() {/*...*/}publicbooleanequals(Objectobj) {/*...*/}publicintamount() {/*...*/}publicStringcurrency() {/*...*/}}21/47實例二:測試碼 [1/2]importjunit.framework.*;publicclassMoneyTestextendsTestCase{ publicMoneyTest(Strings){super(s);} publicvoidtestNullAdd(){ Stringcurr="NTD"; intval1=;
Moneymoney1=newMoney(val1,curr); Moneymoney2=null;//nullvalue Moneymoney3=money1.add(money2); Assert.assertEquals(money1,money3); }22/47實例二:測試碼 [2/2]
publicvoidtestSimpleAdd(){Stringcurr="NTD";intval1=;intval2=345;intval3=val1+val2; Moneymoney1=newMoney(val1,curr); Moneymoney2=newMoney(val2,curr); Moneymoney3=money1.add(money2);
assertEquals(money3,newMoney(val3,curr)); }}23/47java-cplib\junit.jar;.junit.swingui.TestRunnerMoneyTestSuccess24/47Failure 1/225/47Failure 2/226/47Error 1/227/47Error 2/228/47LessonsLearnedGenerate&exercisetestcase(s)Writetest…()method(s)VerifyChooseaAssert.assert…()ChooseaTestRunnerjunit.textui.TestRunnerjunit.swingui.TestRunnerFailurevs.error29/47CaseStudyFixture/context管理Testsuite與進入點GroupingbytasksConfigurationmanagementRegressiontesting30/47junit實例三:FooTestCaseexercise1..*TestRunnerrun1..*FooTesttest1test2…setUp()
tearDown()31/47實例三:測試碼 [1/2]importjunit.framework.*;publicclassMoneyTestextendsTestCase{privateMoneymoney1,money2,money3;publicMoneyTest(Strings) {/*...*/}protectedvoidsetUp(){Stringcurr="NTD";intval1=;intval2=345;money1=newMoney(val1,curr);money2=newMoney(val2,curr);money3=newMoney(val1+val2,curr);}
32/47實例三:測試碼 [2/2]protectedvoidtearDown() {}publicvoidtestNullAdd(){ Moneymoney10=money1.add(null);//nullvalue assertEquals(money1,money10); }publicvoidtestSimpleAdd(){ Moneymoney10=money1.add(money2); assertEquals(money3,money10); }}33/47LessonsLearnedFixtureOverrides
setUp()Overrides
tearDown()Eachtest…()methodisisolated34/47junit實例四FooTestCaseexercise1..*TestRunnerrun1..*FooTesttest1test2…testcaseTestSuitetestsuite35/47實例四:測試碼 [1/3]importjunit.framework.*;publicclassMoneyTestextendsTestCase{privateMoneymoney1,money2,money3;publicMoneyTest(Strings) {/*...*/}protectedvoidsetUp() {/*...*/}publicvoidtestNullAdd() {/*...*/}publicvoidtestSimpleAdd() {/*...*/}36/47實例四:測試碼 [2/3]
//[interactivemode] //entrypointofthewholetestsuite!/* //Version1 publicstaticTestsuite(){
TestSuitesuite=newTestSuite(); suite.addTest(newMoneyTest("testNullAdd")); suite.addTest(newMoneyTest("testSimpleAdd")); returnsuite; }*/ //Version2 publicstaticTestsuite(){ returnnewTestSuite(MoneyTest.class); }37/47實例四:測試碼 [3/3]
//[batchmode] //entrypointofthewholetestsuite! publicstaticvoidmain(Stringargs[]){ junit.textui.TestRunner.run(suite()); }}38/47LessonsLearnedTestcasesuiteWriteasuite()astheinteractivemodeentrypointWriteamain()asthebatchmodeentrypoint39/47實例五:CompositePattern40/47實例五:beforegroupingFootestsuiteexerciseFooTesttest1test2test3…
testcase41/47實例五:groupingbytasksFooexerciseFooTestbasictesttest1test2testsuiterandomtesttest3monkeyteststresstest42/47實例五:compositetestsuitespublicclassMoney_te
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度金融機構(gòu)合規(guī)審查與咨詢服務(wù)合同
- 鋁塑板修補課程設(shè)計
- 音樂游戲中班課程設(shè)計
- 項目管理課程設(shè)計 工程
- 高考日語課程設(shè)計案例
- 自動噴泉控制plc課程設(shè)計
- 資產(chǎn)收購合同
- 個人房屋裝修合同范文
- 水電及消防安裝工程施工合同
- 汽車維修廠勞動合同書
- 公司費用預(yù)算表格模板(詳細版)
- 華為經(jīng)營管理-華為市場營銷體系(6版)
- 2023年中國育齡女性生殖健康研究報告
- 鋼結(jié)構(gòu)加工廠考察報告
- 發(fā)電機檢修作業(yè)指導(dǎo)書
- 薪酬與福利管理實務(wù)-習(xí)題答案 第五版
- 廢舊物資處置申請表
- GB/T 37234-2018文件鑒定通用規(guī)范
- GB/T 31888-2015中小學(xué)生校服
- 質(zhì)量檢查考核辦法
- 云南省普通初中學(xué)生成長記錄-基本素質(zhì)發(fā)展初一-初三
評論
0/150
提交評論