像下面这样的东西.
我想要一种方法来跳过我的dao测试.试图避免定义套件的开销.
使用CI,我希望每晚有一个运行所有测试,另一个5分钟的SCM调查仅运行"快速"测试.
mvn -DskipPattern=**.dao.** test
Run Code Online (Sandbox Code Playgroud)
yeg*_*256 42
让我延伸肖恩的答案.这是你设置的pom.xml:
<properties>
<exclude.tests>nothing-to-exclude</exclude.tests>
</properties>
<profiles>
<profile>
<id>fast</id>
<properties>
<exclude.tests>**/*Dao*.java</exclude.tests>
</properties>
</profile>
</profiles>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>${exclude.tests}</exclude>
</excludes>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
然后在CI中你就像这样开始:
mvn -Pfast test
Run Code Online (Sandbox Code Playgroud)
而已.
Sea*_*oyd 18
好没问题:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<!-- classes that include the name Dao -->
<exclude>**/*Dao*.java</exclude>
<!-- classes in a package whose last segment is named dao -->
<exclude>**/dao/*.java</exclude>
</excludes>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
参考:
(不能通过命令行配置排除,因此如果要有条件地转换此行为,则必须定义配置文件并在命令行上激活该配置文件)
可以使用命令行排除测试;用!排除。
注意:我不确定,但可能需要 2.19.1 或更高版本的 surefire 才能工作。
例子:
这不会运行 TestHCatLoaderEncryption
mvn install '-Dtest=!TestHCatLoaderEncryption'
Run Code Online (Sandbox Code Playgroud)
排除一个包:
mvn install '-Dtest=!org.apache.hadoop.**'
Run Code Online (Sandbox Code Playgroud)
这也可以与正过滤器结合使用。以下将运行 0 个测试:
mvn install '-Dtest=Test*CatLoaderEncryption,!TestHCatLoaderEncryption'
Run Code Online (Sandbox Code Playgroud)