测试的包含和排除

夹杂物

默认情况下,Failsafe Plugin 将自动包含所有具有以下通配符模式的测试类:

  • “**/IT*.java” - 包括其所有子目录和所有以“IT”开头的 java 文件名。
  • “**/*IT.java” - 包括其所有子目录和所有以“IT”结尾的 java 文件名。
  • “**/*ITCase.java” - 包括其所有子目录和所有以“ITCase”结尾的 java 文件名。

如果测试类不符合命名约定,则配置故障安全插件并指定要包含的测试。

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <includes>
            <include>Sample.java</include>
          </includes>
        </configuration>
        <executions>
          <execution>
            <id>integration-test</id>
            <phase>integration-test</phase>
            <goals>
              <goal>integration-test</goal>
            </goals>
          </execution>
          <execution>
            <id>verify</id>
            <phase>verify</phase>
            <goals>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

排除项

There are certain times when some tests are causing the build to fail. Excluding them is one of the best workarounds to continue the build. Exclusions can be done by configuring the excludes property of the plugin.

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <excludes>
            <exclude>**/CircleIT.java</exclude>
            <exclude>**/SquareIT.java</exclude>
          </excludes>
        </configuration>
        <executions>
          <execution>
            <id>integration-test</id>
            <goals>
              <goal>integration-test</goal>
            </goals>
          </execution>
          <execution>
            <id>verify</id>
            <goals>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>