JUnit 軟體測試架構(gòu)_第1頁
JUnit 軟體測試架構(gòu)_第2頁
JUnit 軟體測試架構(gòu)_第3頁
JUnit 軟體測試架構(gòu)_第4頁
JUnit 軟體測試架構(gòu)_第5頁
已閱讀5頁,還剩64頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論