maven-surefire-plugin總結(jié)示例詳解
一、插件簡(jiǎn)介
查看surefire插件的詳細(xì)參數(shù)
mvn surefire:help -Ddetail=true
默認(rèn)的測(cè)試類
"**/Test*.java", "**/*Test.java", "**/*Tests.java", "**/*TestCase.java"
測(cè)試報(bào)告默認(rèn)的路徑
${basedir}/target/surefire-reports二、常用場(chǎng)景
命令行指定執(zhí)行單個(gè)testCase
可以直接省略包路徑
mvn test -Dtest=com.wsl.my.maven.tests.SuffixTestCase mvn test -Dtest=SuffixTestCase
命令行指定執(zhí)行單個(gè)testCase
mvn test -Dtest=SuffixTestCase,SuffixTest
直接跑測(cè)試,不跑其他前置的mvn執(zhí)行周期(compile/resouce/)
mvn surefire:test -Dtest=SuffixTestCase
命令執(zhí)行指定方法
mvn test -Dtest=SuffixTestCase#base
命令執(zhí)行多個(gè)方法
mvn test -Dtest=SuffixTestCase#base,base2
跳過(guò)test
僅跳過(guò)測(cè)試執(zhí)行,會(huì)執(zhí)行testResource和testCompile
mvn install -DskipTests
對(duì)應(yīng)xml形式
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>全部跳過(guò)測(cè)試相關(guān)階段,包括testResource和testCompile和test
mvn install -Dmaven.test.skip=true
某個(gè)Test測(cè)試未通過(guò)后,忽略后續(xù)的測(cè)試不再執(zhí)行
默認(rèn)全部會(huì)執(zhí)行,最后統(tǒng)計(jì)執(zhí)行情況。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
</configuration>
</plugin>執(zhí)行和排除表達(dá)式對(duì)應(yīng)的測(cè)試
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<includes>
<include>Sample.java</include>
<include>**/Test*.java</include>
</includes>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>通過(guò)正則表達(dá)式
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<includes>
<include>%regex[.*(Cat|Dog).*Test.*]</include>
</includes>
</configuration>
</plugin>執(zhí)行依賴包的測(cè)試
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<dependenciesToScan>
<dependency>org.acme:project-a</dependency>
<dependency>org.acme:project-b:test-jar</dependency>
<dependency>org.acme:project-c:*:tests-jdk15</dependency>
</dependenciesToScan>
</configuration>
</plugin>三、結(jié)合junit4
和category一起使用
在測(cè)試類上標(biāo)明category分組,然后配置只有指定的group才需要測(cè)試
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<groups>com.mycompany.SlowTests</groups>
</configuration>
</plugin>
[...]
</plugins> public interface SlowTests{}
public interface SlowerTests extends SlowTests{}public class AppTest {
@Test
@Category(com.mycompany.SlowTests.class)
public void testSlow() {
System.out.println("slow");
}
@Test
@Category(com.mycompany.SlowerTests.class)
public void testSlower() {
System.out.println("slower");
}
@Test
@Category(com.mycompany.FastTests.class)
public void testSlow() {
System.out.println("fast");
}
}到此這篇關(guān)于maven-surefire-plugin總結(jié)的文章就介紹到這了,更多相關(guān)maven-surefire-plugin內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java實(shí)現(xiàn)獲取安卓設(shè)備里已安裝的軟件包
本文給大家介紹的是如何獲取設(shè)備中已經(jīng)安裝的應(yīng)用軟件包的代碼,其核心方法原理很簡(jiǎn)單,我們通過(guò)Android中提供的PackageManager類,來(lái)獲取手機(jī)中安裝的應(yīng)用程序信息2015-10-10
springboot配置多數(shù)據(jù)源后mybatis攔截器失效的解決
這篇文章主要介紹了springboot配置多數(shù)據(jù)源后mybatis攔截器失效的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09
java教程之java程序編譯運(yùn)行圖解(java程序運(yùn)行)
最近重新復(fù)習(xí)了一下java基礎(chǔ),在使用javap的過(guò)程中遇到了一些問(wèn)題,這里便講講對(duì)于一個(gè)類文件如何編譯、運(yùn)行、反編譯的。也讓自己加深一下印象2014-03-03
SpringBoot之RestTemplate在URL中轉(zhuǎn)義字符的問(wèn)題
這篇文章主要介紹了SpringBoot之RestTemplate在URL中轉(zhuǎn)義字符的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
Java8使用LocalDate計(jì)算日期實(shí)例代碼解析
這篇文章主要介紹了Java8使用LocalDate計(jì)算實(shí)例代碼解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04
Java如何調(diào)用wsdl的webservice接口
這篇文章主要介紹了Java如何調(diào)用wsdl的webservice接口問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05

