Maven 2 有没有办法告诉surefire跳过某个包中的测试?

Maven 2 有没有办法告诉surefire跳过某个包中的测试?,maven-2,surefire,Maven 2,Surefire,类似下面的内容 我想要一种在surefire中跳过dao测试的方法。试图避免定义套件的开销 有了CI,我希望每晚有一次运行所有测试,另一次5分钟的SCM轮询只运行“快速”测试 mvn -DskipPattern=**.dao.** test 当然,没问题: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin<

类似下面的内容

我想要一种在surefire中跳过dao测试的方法。试图避免定义套件的开销

有了CI,我希望每晚有一次运行所有测试,另一次5分钟的SCM轮询只运行“快速”测试

mvn -DskipPattern=**.dao.** 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>

org.apache.maven.plugins
>


(无法通过命令行配置排除,因此如果您想有条件地启用此行为,您必须定义一个配置文件并在命令行上激活它)

让我扩展Sean的答案。这是您在
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>

就是这样。

可以使用命令行排除测试;使用
以排除

注意:我不确定,但可能需要2.19.1或更高版本的surefire才能工作

示例:

这将不会运行
TestHCatLoaderEncryption

mvn install '-Dtest=!TestHCatLoaderEncryption'
排除包:

mvn install '-Dtest=!org.apache.hadoop.**'
这也可以与正滤波器结合使用。以下将运行0个测试:

mvn install '-Dtest=Test*CatLoaderEncryption,!TestHCatLoaderEncryption'

请参阅6年后的.

surefire.excludes仍无法在命令行中运行。是否有此机制的文档参考?
mvn install '-Dtest=Test*CatLoaderEncryption,!TestHCatLoaderEncryption'