maven-surefire-plugin總結(jié)示例詳解
一、插件簡介
查看surefire插件的詳細參數(shù)
mvn surefire:help -Ddetail=true
默認的測試類
"**/Test*.java", "**/*Test.java", "**/*Tests.java", "**/*TestCase.java"
測試報告默認的路徑
${basedir}/target/surefire-reports
二、常用場景
命令行指定執(zhí)行單個testCase
可以直接省略包路徑
mvn test -Dtest=com.wsl.my.maven.tests.SuffixTestCase mvn test -Dtest=SuffixTestCase
命令行指定執(zhí)行單個testCase
mvn test -Dtest=SuffixTestCase,SuffixTest
直接跑測試,不跑其他前置的mvn執(zhí)行周期(compile/resouce/)
mvn surefire:test -Dtest=SuffixTestCase
命令執(zhí)行指定方法
mvn test -Dtest=SuffixTestCase#base
命令執(zhí)行多個方法
mvn test -Dtest=SuffixTestCase#base,base2
跳過test
僅跳過測試執(zhí)行,會執(zhí)行testResource和testCompile
mvn install -DskipTests
對應xml形式
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.1.2</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin>
全部跳過測試相關階段,包括testResource和testCompile和test
mvn install -Dmaven.test.skip=true
某個Test測試未通過后,忽略后續(xù)的測試不再執(zhí)行
默認全部會執(zhí)行,最后統(tǒng)計執(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í)行和排除表達式對應的測試
<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>
通過正則表達式
<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í)行依賴包的測試
<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一起使用
在測試類上標明category分組,然后配置只有指定的group才需要測試
<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"); } }
到此這篇關于maven-surefire-plugin總結(jié)的文章就介紹到這了,更多相關maven-surefire-plugin內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
一文帶你掌握Java開發(fā)者如何接入并使用DeepSeek
對于Java開發(fā)者來說,將DeepSeek集成到項目中,可以極大地提升數(shù)據(jù)處理和分析的效率,下面小編就來為大家介紹一下具體的調(diào)用方法吧2025-03-03java數(shù)據(jù)結(jié)構(gòu)實現(xiàn)機器人行走
這篇文章主要為大家詳細介紹了java數(shù)據(jù)結(jié)構(gòu)實現(xiàn)機器人行走,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01解讀RedisTemplate的各種操作(set、hash、list、string)
這篇文章主要介紹了解讀RedisTemplate的各種操作(set、hash、list、string),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-12-12淺談controller中調(diào)用多個service方法的問題
這篇文章主要介紹了淺談controller中調(diào)用多個service方法的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02SpringBoot中maven項目打成war包部署在linux服務器上的方法
這篇文章主要介紹了SpringBoot中maven項目打成war包部署在linux服務器上的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-05-05Spring @CrossOrigin 注解原理實現(xiàn)
這篇文章主要介紹了Spring @CrossOrigin 注解原理實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-07-07