版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
JUnit介紹TestingframeworkwrittenbyErichGammaandKentBeckOpenSourceHostedonSourceForgeLanguagesupportSmalltalk,Java,C++,Perl,Python,etc.IDESupportJBuilder,VisualAge,etc.1/47WhatisSoftwareTesting?Theexecutionofcodeusingcombinationsofinputandstateselectedtorevealbugs.Theprocessofdevisingandexecutingatestsuitethatattemptstocausefailures,increasingourconfidencethatfailuresareunlikely.2/47軟件測(cè)試工具分類(lèi)分類(lèi)實(shí)例reviews&inspectionsCompuwareDevPartnertestplanningRationalSuiteTestStudiotestdesign&developmenttestexecution&evaluationcapture/playbackcoverageanalysisCompuwareDevPartnerRationalSuiteTestStudioBorlandOptimizeitmemorytestingCompuwareDevPartnerRationalSuiteTestStudiotestcasemanagementsumulations&performanceprofilertestsupport3/47JUnit定位JUnitis…JUnitisnot…scope單元測(cè)試綜合測(cè)試,組合測(cè)試testware模塊完整系統(tǒng)level工具方法輪testcase手動(dòng)產(chǎn)生自動(dòng)產(chǎn)生testdriver/script部份手寫(xiě)全自動(dòng)4/47JUnitFramework5/47junitHowtoTestwithJUnit?FooTestCaseexercise1..*TestRunnerrun1..*FooTesttest1test2…6/47Questions…怎樣測(cè)試? strategy多少測(cè)試才夠? coverage流程? process工具影響? mediumismessage7/47DesignGoalsofJUnitEasytouseRequiresnomoreworkthanabsolutelynecessarytowriteanewtestLeveragesexistingteststocreatenewonesReusablefixturestorundifferenttestsRetainsvaluesoftestsovertimeCombinestestsfromvariousauthorsandrunthemtogetherwithoutfearofinterference8/47CaseStudy自動(dòng)產(chǎn)生測(cè)試框架UsingBorlandJBuilder6.0最簡(jiǎn)單測(cè)試實(shí)例9/47實(shí)例一FoojunitTestCaseexercise1..*FooTesttest1test2…10/47實(shí)例一:簡(jiǎn)單待測(cè)程序publicclassMoney{privateintfAmount;privateStringfCurrency;publicMoney(intamount,Stringcurrency){fAmount=amount;fCurrency=currency;}publicMoneyadd(Moneym){returnnewMoney(amount()+m.amount(),currency());}publicintamount() {returnfAmount;}publicStringcurrency() {returnfCurrency;}}11/47實(shí)例一:產(chǎn)生測(cè)試框架 [1/7]BorlandJBuilder6.012/47實(shí)例一:產(chǎn)生測(cè)試框架 [2/7]BorlandJBuilder6.013/47實(shí)例一:產(chǎn)生測(cè)試框架 [3/7]BorlandJBuilder6.014/47實(shí)例一:產(chǎn)生測(cè)試框架 [4/7]BorlandJBuilder6.015/47實(shí)例一:產(chǎn)生測(cè)試框架 [5/7]BorlandJBuilder6.016/47實(shí)例一:產(chǎn)生測(cè)試框架 [6/7]BorlandJBuilder6.017/47實(shí)例一:產(chǎn)生測(cè)試框架 [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實(shí)例二FooTestCaseexercise1..*TestRunnerrunFooTesttest1test2…20/47實(shí)例二:測(cè)試碼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實(shí)例二:測(cè)試碼 [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實(shí)例二:測(cè)試碼 [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與進(jìn)入點(diǎn)GroupingbytasksConfigurationmanagementRegressiontesting30/47junit實(shí)例三:FooTestCaseexercise1..*TestRunnerrun1..*FooTesttest1test2…setUp()
tearDown()31/47實(shí)例三:測(cè)試碼 [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實(shí)例三:測(cè)試碼 [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實(shí)例四FooTestCaseexercise1..*TestRunnerrun1..*FooTesttest1test2…testcaseTestSuitetestsuite35/47實(shí)例四:測(cè)試碼 [1/3]importjunit.framework.*;publicclassMoneyTestextendsTestCase{privateMoneymoney1,money2,money3;publicMoneyTest(Strings) {/*...*/}protectedvoidsetUp() {/*...*/}publicvoidtestNullAdd() {/*...*/}publicvoidtestSimpleAdd() {/*...*/}36/47實(shí)例四:測(cè)試碼 [2/3]
//[interactivemode] //entrypointofthewholetestsuite!/* //Version1 publicstaticTestsuite(){
TestSuitesuite=newTestSuite(); suite.addTest(newMoneyTest("testNullAdd")); suite.addTest(newMoneyTest("testSimpleAdd")); returnsuite; }*/ //Version2 publicstaticTestsuite(){ returnnewTestSuite(MoneyTest.class); }37/47實(shí)例四:測(cè)試碼 [3/3]
//[batchmode] //entrypointofthewholetestsuite! publicstaticvoidmain(Stringargs[]){ junit.textui.TestRunner.run(suite()); }}38/47LessonsLearnedTestcasesuiteWriteasuite()astheinteractivemodeentrypointWriteamain()asthebatchmodeentrypoint39/47實(shí)例五:CompositePattern40/47實(shí)例五:beforegroupingFootestsuiteexerciseFooTesttest1test2test3…
testcase41/47實(shí)例五:groupingbytasksFooexerciseFooTestbasictesttest1test2testsuiterandomtesttest3monkeyteststresstest42/47實(shí)例五:compositetestsuitespublicclassMoney_te
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 浙江師范大學(xué)《規(guī)范字與書(shū)法》2023-2024學(xué)年第一學(xué)期期末試卷
- 鄭州體育職業(yè)學(xué)院《視頻傳播實(shí)務(wù)》2023-2024學(xué)年第一學(xué)期期末試卷
- 長(zhǎng)春師范大學(xué)《社會(huì)治理》2023-2024學(xué)年第一學(xué)期期末試卷
- 榆林職業(yè)技術(shù)學(xué)院《戶(hù)外拓展與定向運(yùn)動(dòng)》2023-2024學(xué)年第一學(xué)期期末試卷
- 食用菌栽培基質(zhì)廢棄物降解
- 碩士職場(chǎng)競(jìng)爭(zhēng)力
- 秋分節(jié)氣與糧食安全
- 農(nóng)業(yè)創(chuàng)新路演
- 學(xué)校文化建設(shè)上墻標(biāo)語(yǔ)
- 會(huì)計(jì)辭職報(bào)告范文
- 華為經(jīng)營(yíng)管理-華為市場(chǎng)營(yíng)銷(xiāo)體系(6版)
- 2023年中國(guó)育齡女性生殖健康研究報(bào)告
- 鋼結(jié)構(gòu)加工廠(chǎng)考察報(bào)告
- 發(fā)電機(jī)檢修作業(yè)指導(dǎo)書(shū)
- 薪酬與福利管理實(shí)務(wù)-習(xí)題答案 第五版
- 廢舊物資處置申請(qǐng)表
- GB/T 37234-2018文件鑒定通用規(guī)范
- GB/T 31888-2015中小學(xué)生校服
- 質(zhì)量檢查考核辦法
- 云南省普通初中學(xué)生成長(zhǎng)記錄-基本素質(zhì)發(fā)展初一-初三
- 外科醫(yī)師手術(shù)技能評(píng)分標(biāo)準(zhǔn)
評(píng)論
0/150
提交評(píng)論