4

我有一个项目,测试分为单元和集成阶段。我让它运行 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 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))

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

更新: 正如我所建议的那样,我尝试了surefire:

<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 来避免初始化错误。

4

2 回答 2

3

首先检查是否有相同的父 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 进行集成测试,它包含一个特定的目标验证 ,旨在随后检查集成测试的结果。但是您需要通过执行块单独配置它并绑定到特定的生命周期阶段。

于 2013-02-12T10:31:23.757 回答
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>
于 2013-02-12T15:05:13.020 回答