maven使用surefire excludeTests选项排除测试

时间:2017-05-01 03:08:42

标签: java maven maven-3 maven-surefire-plugin

我有一个包含子项目的大型项目,并希望使用excludesFile来排除测试失败,并在测试修复之前忽略它们。

我相信使用surefire插件excludesFile选项here可能有办法实现这一目标。

我对maven非常陌生,想得到一些关于如何实现这一目标的例子或指示。

1 个答案:

答案 0 :(得分:1)

使用excludesFile选项,

  1. 创建一个包含要排除的测试文件的文件名模式的文件。
    示例:使用以下2行在src / main / resources / exclude.txt创建文件。
    ** / * 1.java
    ** / * 2.java
  2. 在maven-surefile-plugin配置中添加以下内容。

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <excludesFile>src/test/resources/exclude.txt</excludesFile>
            </configuration>
        </plugin>
    </plugins>
    

  3. 你已经完成了。所有以1.java和2.java结尾的测试文件都将被排除。

  4. 还有其他方法可以通过在maven-surefire-plugin中使用配置来排除执行中的任何测试。

    示例:

    <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20</version>
        <configuration>
          <excludes>
            <exclude>**/TestCircle.java</exclude>
            <exclude>**/TestSquare.java</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
    

    可以找到更多信息here