我有一个项目,测试分为单元和集成阶段。我让它运行 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 来避免初始化错误。