失败测试时,Maven + Surefire返回码为0

时间:2013-02-12 10:00:49

标签: maven surefire

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

这是mvn integration-test的结果:

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 install的结果是相同的 结果:

Tests in error: 
  Info about failed tests

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

$ echo $?
0

Surefire配置如下:

<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>

我正在阅读有关maven返回代码的其他主题,但理论上相关的错误应该在我的maven版本中修复(Apache 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>

我需要surefire-junit来避免初始化错误。

2 个答案:

答案 0 :(得分:2)

我设法让它使用两种不同的配置,使用组并使用确保使用文件夹

<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>

答案 1 :(得分:1)

首先检查是否有相同的父pom配置:

<testFailureIgnore>true</testFailureIgnore>
某处...您可以通过以下方式查看:

mvn help:effective-pom

此外,您正在尝试使用maven-surefire-plugin运行集成测试,这是完全错误的。对于集成测试,请使用maven-failsafe-plugin。另一件事是以正确的方式命名集成测试,如IT * .java,* IT.java等。

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

对不起啊。监督你正在谈论集成测试。如果您正确使用maven-failsafe-plugin进行集成测试,则它包含特定目标verify 这是为了检查之后的集成测试的结果。但是您需要通过执行块单独配置它并绑定到特定的生命周期阶段。

相关问题