Cobertura + Failsafe:即使集成测试失败,也要使“ MVN清理站点”继续进行

时间:2018-11-11 17:29:52

标签: java maven java-8 maven-failsafe-plugin maven-cobertura-plugin

我有一个Java8 / Maven / Spring Boot项目,涉及maven-failsafe-plugin(为了在*IT.java中运行集成测试,而与*Test.java中的单元测试分开)和{{1} }。

问题是如果集成测试失败,cobertura-maven-plugin不能得出结论,而如果单元测试失败,则mvn clean site很好。

为重现此内容,我首先添加了一个包含以下内容的mvn clean site

src/test/java/app/FailingTest.java

package app; import org.junit.Test; import static org.junit.Assert.fail; public class FailingTest { @Test public void failingTest () { fail(); } } 产生:

mvn clean site

然后我将该类重命名为... [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running app.FailingTest [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.063 s <<< FAILURE! - in app.FailingTest [ERROR] failingTest(app.FailingTest) Time elapsed: 0.005 s <<< FAILURE! java.lang.AssertionError at app.FailingTest.failingTest(FailingTest.java:11) ... [INFO] Cobertura Report generation was successful. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ ,然后src/test/java/app/FailingIT.java产生:

mvn clean site

如何解决此问题?

我的... [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running app.FailingIT [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.031 s <<< FAILURE! - in app.FailingIT [ERROR] failingTest(app.FailingIT) Time elapsed: 0.005 s <<< FAILURE! java.lang.AssertionError at app.FailingIT.failingTest(FailingIT.java:11) ... [INFO] --- maven-failsafe-plugin:2.22.1:verify (default) @ example-project --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ 如下:

pom.xml

1 个答案:

答案 0 :(得分:0)

maven-failsafe-plugin造成构建失败的原因。您的pom.xml中明确指出了原因:

<goal>integration-test</goal>

如果测试确实是集成测试( IT ),则必须对其进行修复;否则,如果它不是集成测试,则可以将其重命名为单元测试( UT ),但仍然可以解决它:)

消除此错误的另一种较差的方法可能是在pom.xml中一起注释掉故障安全插件声明,使其变为非活动状态。我建议不要这样做。