在失败的测试中,Maven + Surefire返回代码为0
问题描述:
我有一个项目,测试分为单元和集成阶段。我有它运行buildbot和问题是,即使在测试失败maven返回代码是0,所以buildbot构建是成功的。在失败的测试中,Maven + Surefire返回代码为0
这是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>
我读过关于maven re的其他线程转向代码,但理论上相关的错误应该在我的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>
我需要的神火,JUnit来避免初始化错误。
答
我设法把它与两种不同的配置工作,使用组并使用文件夹只用万无一失的
<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>
答
如果是相同配置的父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插件进行集成测试,它将包含一个特定目标verify ,该目标旨在检查之后的集成测试结果。但是您需要通过执行块单独配置并绑定到特定的生命周期阶段。
不,我没有testFailureIgnore这个,我会尝试故障安全 – hithwen 2013-02-12 10:48:32
啊...在我身边的误解,因为你使用的集成测试需要单独配置,就像我在最后一段中写的那样。 – khmarbaise 2013-02-12 11:18:39
我尝试了故障安全,并且仍然得到0 retcode – hithwen 2013-02-12 12:41:41