类似于以下内容。
我想要一种在万无一失的情况下跳过我的 dao 测试的方法。试图避免定义套件的开销。
对于 CI,我希望每晚都有一个运行所有测试的晚上,以及另一个 5 分钟的 SCM 轮询,它只运行“快速”测试。
mvn -DskipPattern=**.dao.** test
让我扩展肖恩的答案。这是你设置的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>
然后在 CI 中你像这样启动它们:
mvn -Pfast test
而已。
好没问题:
<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>
参考:
(排除不能通过命令行配置,所以如果你想有条件地打开这个行为,你必须定义一个配置文件并在命令行上激活它)
可以使用命令行排除测试;用来!
排除。
注意:我不确定,但可能需要 2.19.1 或更高版本的 surefire 才能工作。
例子:
这不会运行TestHCatLoaderEncryption
mvn install '-Dtest=!TestHCatLoaderEncryption'
排除包:
mvn install '-Dtest=!org.apache.hadoop.**'
这也可以与正过滤器结合使用。以下将运行 0 个测试:
mvn install '-Dtest=Test*CatLoaderEncryption,!TestHCatLoaderEncryption'