maven-failsafe-plugin失败并建立成功?

时间:2012-09-05 10:13:50

标签: maven maven-plugin maven-failsafe-plugin

我想使用maven-failsafe-plugin来运行一些集成测试。如果任何测试失败,我希望Maven失败,而不是构建成功。

Tests run: 103, Failures: 1, Errors: 0, Skipped: 26
[INFO] BUILD SUCCESS*


如何配置它,构建不成功是什么?

我的故障安全插件配置为:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>${failsafe.version}</version>
    <configuration>
        <systemProperties>
            <CI_INTEGRATION_OVERRIDE_PATH>${basedir}/..</CI_INTEGRATION_OVERRIDE_PATH>
        </systemProperties>
        <includes>
            <include>**/integration/**/*.java</include>
        </includes>
        <excludes>
            <exclude>**/integration/**/*TestSuite.java</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <id>integration-test</id>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

3 个答案:

答案 0 :(得分:10)

正如Andrew所指出的,正确的解决方案是按预期使用故障保护。集成测试目标专门设计为不会使构建失败。如果您想使构建失败,请致电mvn verifymvn failsafe:verify

要使verify目标起作用,它需要读取集成测试的结果,默认情况下将其写入${project.build.directory}/failsafe-reports/failsafe-summary.xml,以确保生成。

此外,您必须确保将maven-failsafe-plugin配置绑定到integration-test目标和verify部分中的executions目标。

未能添加其中任何一个将导致maven成功构建,而不是在集成测试失败时失败。

答案 1 :(得分:2)

由于您正在运行mvn clean install,因此integration-testverify阶段都应该执行。根据故障安全插件文档,failsafe:integration-testfailsafe:verify目标与这些阶段绑定,因此我不认为需要额外调用failsafe:integration-test

尽管如此,我不确定我是否相信故障安全插件文档。我今年早些时候有人answered a similar question。事实证明,他必须明确地将每个目标绑定到正确的阶段,然后failafe按预期工作。可能值得一试。

答案 2 :(得分:1)

溶液。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <skip>true</skip>
  </configuration>
  <executions>
    <execution>
      <id>unit-test</id>
      <phase>test</phase>
      <goals>
        <goal>test</goal>
      </goals>
      <configuration>
        <skip>false</skip>
        <excludes>
          <exclude>**/*IntegrationTest.java</exclude>
        </excludes>
      </configuration>
      </execution>
      <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>test</goal>
        </goals>
        <configuration>
          <skip>false</skip>
          <enableAssertions>false</enableAssertions>
          <includes>
            <include>**/*IntegrationTest.java</include>
          </includes>
          <systemPropertyVariables>
            <integration>${integration}</integration>
          </systemPropertyVariables>
        </configuration>
      </execution>
    </executions>
</plugin>