maven-surefire-plugin總結(jié)示例詳解
一、插件簡(jiǎn)介
查看surefire插件的詳細(xì)參數(shù)
mvn surefire:help -Ddetail=true
默認(rèn)的測(cè)試類(lèi)
"**/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í)行依賴(lài)包的測(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è)試類(lèi)上標(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)文章
一文帶你掌握J(rèn)ava開(kāi)發(fā)者如何接入并使用DeepSeek
對(duì)于Java開(kāi)發(fā)者來(lái)說(shuō),將DeepSeek集成到項(xiàng)目中,可以極大地提升數(shù)據(jù)處理和分析的效率,下面小編就來(lái)為大家介紹一下具體的調(diào)用方法吧2025-03-03如何發(fā)布jar包到maven中央倉(cāng)庫(kù)
這篇文章主要介紹了發(fā)布jar包到maven中央倉(cāng)庫(kù)的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-12-12java數(shù)據(jù)結(jié)構(gòu)實(shí)現(xiàn)機(jī)器人行走
這篇文章主要為大家詳細(xì)介紹了java數(shù)據(jù)結(jié)構(gòu)實(shí)現(xiàn)機(jī)器人行走,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01IDEA 離線(xiàn)遷移Springboot工程的方法步驟
這篇文章主要介紹了IDEA 離線(xiàn)遷移Springboot工程的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06解讀RedisTemplate的各種操作(set、hash、list、string)
這篇文章主要介紹了解讀RedisTemplate的各種操作(set、hash、list、string),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12淺談controller中調(diào)用多個(gè)service方法的問(wèn)題
這篇文章主要介紹了淺談controller中調(diào)用多個(gè)service方法的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02SpringBoot中maven項(xiàng)目打成war包部署在linux服務(wù)器上的方法
這篇文章主要介紹了SpringBoot中maven項(xiàng)目打成war包部署在linux服務(wù)器上的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05Spring @CrossOrigin 注解原理實(shí)現(xiàn)
這篇文章主要介紹了Spring @CrossOrigin 注解原理實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07