Maven的+神火返回代码为0的测试失败(Maven + Surefire return code

2019-08-16 22:27发布

我有一个在单元和集成阶段分组测试项目。 我有它运行buildbot,问题是,即使在测试失败的Maven返回码为0,因此buildbot构建是成功的。

这是MVN集成测试的结果:

Results :

Tests in error: 
 Info about failed tests

Tests run: 5, Failures: 0, Errors: 5, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 19 seconds
[INFO] Finished at: Tue Feb 12 09:43:53 UTC 2013
[INFO] Final Memory: 36M/97M
[INFO] ------------------------------------------------------------------------

$ echo $?
0

结果为MVN安装是没有建立成功部分结果是一样的:

Tests in error: 
  Info about failed tests

Tests run: 5, Failures: 0, Errors: 5, Skipped: 0

$ echo $?
0

神火配置是这样的:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.13</version>
  <configuration>
    <printSummary>true</printSummary>
    <excludedGroups>com.testlib.IntegrationTest</excludedGroups>
  </configuration>
  <executions>
    <execution>
    <id>unit-tests</id>
    <phase>test</phase>
    <goals>
      <goal>test</goal>
    </goals>
    <configuration>
          <excludedGroups>com.testlib.IntegrationTest</excludedGroups>
    </configuration>
    </execution>
    <execution>
    <id>integration-tests</id>
    <phase>integration-test</phase>
    <goals>
      <goal>test</goal>
    </goals>
    <configuration>
      <includes>
            <groups>com.testlib.IntegrationTest</groups>
      </includes>
        </configuration>
    </execution>
  </executions>
</plugin>

我已经阅读有关行家返回代码,但在理论上相关的bug其他线程应固定在我的Maven版本(阿帕奇Maven的2.2.1(rdebian-8))

有没有什么办法改变这种行为?

更新:由于建议我试图与神火:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.13</version>
    <dependencies>
        <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit47</artifactId>
        <version>2.13</version>
        </dependency>
    </dependencies>
    <configuration>
        <groups>com.testlib.IntegrationTest</groups>
    </configuration>
    <executions>
        <execution>
            <goals>
            <goal>integration-test</goal>
            <goal>verify</goal>
            </goals>
            <configuration>
                <includes>
                  <include>**/*.class</include>
                </includes>
            </configuration>
        </execution>
    </executions>

我需要的神火,JUnit来避免初始化错误。

Answer 1:

我设法把它与两种不同的配置工作,使用组并使用只用万无一失的文件夹

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.13</version>
    <configuration><excludedGroups>com.testlib.IntegrationTest</excludedGroups>
    </configuration>
    <executions>
        <execution>
            <id>integration-test</id>
            <phase>integration-test</phase>
            <goals>
                goal>test</goal>
            </goals>
            <configuration>
              <skip>false</skip>
                      <excludedGroups>com.biicode.testlib.UnitTest</excludedGroups>
                      <groups>com.testlib.IntegrationTest</groups>
            </configuration>
        </execution>
    </executions>

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/integration/*.java</exclude>
        </excludes>
    </configuration>
    <executions>
    <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
            <goal>test</goal>
        </goals>
        <configuration>
        <skip>false</skip>
        <excludes>
            <exclude>none</exclude>
        </excludes>
        <includes>
            <include>**/integration/*.java</include>
        </includes>
    </configuration>
  </execution>
  </executions>
</plugin>


Answer 2:

首先检查是否存在该配置相同的父POM:

<testFailureIgnore>true</testFailureIgnore>

地方......你可以通过检查:

mvn help:effective-pom

此外,您正在尝试运行与集成测试Maven的万无一失,插件,这是完全错误的。 对于集成测试使用Maven的故障保护,插件 。 另一件事是在像IT *的.java,* IT.java权等方式来命名你的集成测试

另一件事是你为什么要使用这样一个旧版本的Maven Maven的检查3.0.4。

不好意思啊。 你说的是集成测试监督。 如果你正确使用Maven的故障保护,插件集成测试它包含了一个特定的目标验证其目的是事后检查集成测试的结果。 但是,你需要单独配置,其经执行块和绑定到特定的生命周期阶段。



文章来源: Maven + Surefire return code is 0 on failed tests