學(xué)習(xí)maven之surefire pluginjunit篇如果你執(zhí)行過(guò)mvntest或者其他命令時(shí)跑了測(cè)_第1頁(yè)
學(xué)習(xí)maven之surefire pluginjunit篇如果你執(zhí)行過(guò)mvntest或者其他命令時(shí)跑了測(cè)_第2頁(yè)
學(xué)習(xí)maven之surefire pluginjunit篇如果你執(zhí)行過(guò)mvntest或者其他命令時(shí)跑了測(cè)_第3頁(yè)
學(xué)習(xí)maven之surefire pluginjunit篇如果你執(zhí)行過(guò)mvntest或者其他命令時(shí)跑了測(cè)_第4頁(yè)
學(xué)習(xí)maven之surefire pluginjunit篇如果你執(zhí)行過(guò)mvntest或者其他命令時(shí)跑了測(cè)_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

執(zhí)試用例的插件,不顯示配置就會(huì)用默認(rèn)配置。這個(gè)插件的surefire:test命令會(huì)默認(rèn)綁定maven執(zhí)行的test階段?!皊ources,process-test-sources,generate-test-resources,process-test-resources, pile,process-test-classes,test,prepare-package,package,pre-integration-test,integration-test,post-integration-test,verify,install,deploy]配置ififtheJUnitversionintheproject>=4.7andtheparallelattributehasANYvalueusejunit47providerifJUnit>=4.0ispresentusejunit4provideruse publicclassApp{publicintadd(inta,intb){returna+b;}publicintsubtract(inta,intb){returna-b;}}importorgjunitAfter;importorg.junit.Assert;importorg.junit.Before;importpublicclassAppTest{privateAppapp;@BeforepublicvoidsetUp(){app=newApp();}@TestpublicvoidtestAdd()throwsInterruptedException{inta=1;intb=2;intresult=app.add(a,b);Assert.assertEquals(a+b,result);}@TestpublicvoidtestSubtract()throwsInterruptedException{inta=1;intb=2;intresult=app.subtract(a,b);Assert.assertEquals(a-b,result);}@AfterpublicvoidtearDown()throwsException{}}``````bashqyfmac$mvntest[INFO]Scanningforprojects... tformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildistformdependent![INFO]skipnonexistingresourceDirectory/Users/qyfmac/git/learn-maven/src/main/resources[INFO][INFO]--- pile( pile)@learn-maven---[INFO]Changesdetected- pilingthemodule![WARNING]Fileencodinghasnotbeenset,usingtformencodingUTF-8,ie.buildistformdependent![INFO]Compiling1sourcefileto/Users/qyfmac/git/learn-maven/target/classes[INFO][INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@learn-maven---[WARNING]Usingtformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildistformdependent![INFO]skipnonexistingresourceDirectory/Users/qyfmac/git/learn-maven/src/test/resources[INFO][INFO]---compiler-plugin3.1 pile( pile)@learn-maven---[INFO]Changesdetected- pilingthemodule![WARNING]Fileencodinghasnotbeenset,usingtformencodingUTF-8,i.e.buildistformdependent![INFO]Compiling2sourcefilesto/Users/qyfmac/git/learn-maven/target/test-classes[INFO][INFO]---maven-surefire-plugin:2.19:test(default-test)@learn-maven---[WARNING]TheparameterforkModeisdeprecatedsinceversion2.14.UseforkCountandreuseForksinstead.[INFO]Surefirereportdirectory:/Users/qyfmac/git/learn-maven/target/surefire-reports[INFO]UsingconfiguredproviderorgTESTRunningcom.qyf404.learn.maven.AppTestTestsrun:2,Failures:0,Errors:0,Skipped:0,Timeelapsed:0.003sec-inTestsrun:2,Failures:0,Errors:0,Skipped: -----------------[INFO]Totaltime:2.622s[INFO]Finishedat:2015-12-01T11:36:04+0800[INFO]FinalMemory:14M/228M[INFO]----------------------??????????t??,n?????????? ?n?.31.?????????configuration???或bashbashqyfmac$mvntest-或bashbashqyfmac$mvntest-,,

如果是配置skipTestsconfiguration的配置優(yōu)先級(jí)最高,命令中得配置次之properties的配置最低如果是配置maven.test.skip,命令中得配置優(yōu)先級(jí)最高,properties的配置最低.即??>和.即importorgjunitAfter;importorg.junit.Assert;importorg.junit.Before;importorg.junit.Test;importorg.junit.runner.RunWith;import@RunWith(JUnit4.class)publicclassApp2Test{privateAppapp;@BeforepublicvoidsetUp(){app=newApp();}@TestpublicvoidtestAdd()throwsInterruptedException{inta=1;intb=2;intresult=app.add(a,b);Thread.currentThread().sleep(1000);Assert.assertEquals(a+b,result);}@AfterpublicvoidtearDown()throwsException{}}mvntest是這樣的,它執(zhí)行了全部測(cè)試用例```bashqyfmac$mvntest[INFO]Scanningforprojects... TESTRunningcom.qyf404.learn.maven.App2TestTestsrun:1,Failures:0,Errors:0,Skipped:0,Timeelapsed:1.004sec-incom.qyf404.learn.maven.App2TestRunningcom.qyf404.learn.maven.AppTestTestsrun:2,Failures:0,Errors:0,Skipped:0,Timeelapsed:0sec-inTestsrun:3,Failures:0,Errors:0,Skipped: -----------------[INFO]Totaltime:2.773s[INFO]Finishedat:2015-12-01T14:57:00+0800[INFO]FinalMemory:9M/156M[INFO]-------------------------```bashqyfmac$mvntest-Dtest=App2Test[INFO]Scanningforprojects... TESTRunningcom.qyf404.learn.maven.App2TestTestsrun:1,Failures:0,Errors:0,Skipped:0,Timeelapsed:1.003sec-inTestsrun:1,Failures:0,Errors:0,Skipped: -----------------[INFO]Totaltime:3.061s[INFO]Finishedat:2015-12-01T14:58:59+0800[INFO]FinalMemory:9M/156M[INFO]------------------------mvntestmvntest-Dtest=App2Test,AppTest也可以用antmvntestDtest=*2TestmvntestDtest=???2Test- 上面說(shuō)了,在執(zhí)行命令時(shí)可以指定執(zhí)行哪個(gè)或哪些測(cè)試用例,其實(shí)在pom.xml里也是可以配置的.比如打包時(shí)執(zhí)試用例AppTest,不執(zhí)行App2Test,可以這junit47</artifactId><version>2.19</version></dependency></dependencies><configuration>><include<exclude里的配置方式和-Dtest后面的一樣可以配置表達(dá)式:指定具體類(lèi)<include>AppTest</include.>>>> ]>]>更復(fù)雜的%regex[expr表達(dá)式<include>%regex[com.qyf404.[learn|test].*Test.class]</include,中間的方括號(hào)表示或的概念,即更復(fù)雜的%regex[expr表達(dá)式<include>!%regex[com.qyf404.*.*2Test.class]</include,這里面的嘆號(hào)表示否定,即包含不符合該表達(dá)]>更復(fù)雜的%regex[expr表達(dá)式里最好不要有問(wèn)號(hào)[?],而且匹配的是類(lèi)的全類(lèi)名.不可以指定具體方法,<include>*Test#testAdd</include. 和 importorgjunitAfter;importorg.junit.Assert;importorg.junit.Before;importorg.junit.Test;importpublicclassAppTest{privateAppapp;@BeforepublicvoidsetUp(){app=newApp();}@Test@Category(com.qyf404.learnmaven.FastTests.class)publicvoidtestAdd()throwsInterruptedException{inta=1;intb=2;intresult=app.add(a,b);System.out.println("---"+Thread.currentThread().getName());Assert.assertEquals(a+b,result);}@Test()@Category(com.qyf404.learn.maven.SlowTests.class)publicvoidtestSubtract()throwsInterruptedException{inta=1;intb=2;intresult=app.subtract(a,b);System.out.println("---"+Thread.currentThread().getName());Assert.assertEquals(a-b,result);}@AfterpublicvoidtearDown()throwsException{}}pomxml里這么配置在執(zhí)行Testsrun:3,Failures:1,Errors:0,Skipped:01.這個(gè)數(shù)字其實(shí)只要是一個(gè)大于零的數(shù)就可以.表達(dá)的意思就是當(dāng)有N.2表示當(dāng)某個(gè)測(cè)試用例執(zhí)行失敗以后,還可以重新執(zhí)行2次,有一次執(zhí)行成功就認(rèn)為測(cè)試用例執(zhí)行成功.2只要是一個(gè)大于零的整數(shù)就可以,,在maven的執(zhí)行報(bào)告中會(huì)多一個(gè)Flakes.TESTRunningcom.qyf404.learn.maven.App2TestTestsrun:3,Failures:2,Errors:0,Skipped:0,Timeelapsed:3.023sec<<<FAILURE!-incom.qyf404.learn.maven.App2TesttestAdd(com.qyf404.learnmaven.App2Test)Timeelapsed:1.012sec<<<FAILURE!java.lang.AssertionError:expected:<2>butwas:<3>atcom.qyf404.learn.maven.App2Test.testAdd(App2Test.java32)testAdd(com.qyf404learn.maven.App2Test)Timeelapsed:1.006sec<<<FAILURE!java.lang.AssertionError:expected:<2>butwas:<3>atcom.qyf404.learn.maven.App2TesttestAdd(App2Test.java:32)Runningcom.qyf404.learn.maven.AppTestTestsrun:2,Failures:0,Errors:0,Skipped:0,Timeelapsed:0sec-incom.qyf404.learnmaven.AppTestResults:Flakedtests:com.qyf404.learn.maven.App2TesttestAdd(com.qyf404.learnmaven.App2Test)Run1:App2Test.testAdd:32expected:<2>butwas:<3>Run2:App2TesttestAdd:32expected:<2>butwas:<3>Run3:PASSTestsrun:3,Failures:0,Errors:0,Skipped:0,Flakes:1 以在命令中加入-X或--debug來(lái)打印 執(zhí)行maven命令mvn-Dmaven.surefire.debugtest以開(kāi)啟調(diào)試模式.當(dāng)然也可以用完整令來(lái)指定端口bashmvn-Dmaven.surefire.debug="-XdebugXrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005Xnoagentpiler=NONE"piler=NONE" tformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildistformdependent![INFO]skipnonexistingresourceDirectory pile pile)@learn-maven---Nothingtocompile-allclassesareuptodate[INFO][INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@learn-maven---[WARNING]Usingtformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildistformdependent![INFO]skipnonexistingresourceDirectory/Users/qyfmac/git/learn-maven/src/test/resources[INFO][INFO]--- pile( pile)@learn-maven---[INFO]Nothingtocompile-allclassesareuptodate[INFO][INFO]---maven-surefire-plugin2.19:test(default-test)@lear

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 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ì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論