當遇到以下場景:
其他人寫的單元測試影響統計結果
一些需要調用外部接口的測試暫不運行
需要在非本機環境上運行一些不回滾的單元測試
則有必要選擇以下方法跳過部分測試。
1、在測試用例前加上注解 @Ignore,例如:
1
2
3
4
5
6
7
|
@Ignore @Test public void testGetAreaChirldren() { Area area = addArea(); List< AreaTreeVO > listAreaTreeVOs = areaService.getAreaChirldren(area.getId()); Assert.assertNotNull("有子節點", listAreaTreeVOs); } |
2、在編寫maven構建命令時加上 -Dtest=**,則執行指定的測試用例,*為通配符,例如:
clean test -Dtest=*ServiceTest
3、在pom.xml文件中,找到maven的單元測試插件,進行如下配置:
1
2
3
4
5
6
7
8
9
10
11
|
< plugin > < groupId >org.apache.maven.plugins</ groupId > < artifactId >maven-surefire-plugin</ artifactId > < version >${maven-surefire.ver}</ version > < configuration > < excludes > < exclude >com/bc/pmpheep/back/**</ exclude > < exclude >com/bc/pmpheep/utils/**</ exclude > </ excludes > </ configuration > </ plugin > |
以上這篇Maven構建時跳過部分測試的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/gugia/archive/2017/11/21/7875429.html