Maven Cobertura:单元测试失败但构建成功
我已经在我的 pom 中配置了 cobertura 代码覆盖率:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<instrumentation>
<excludes>
<exclude>**/*Exception.class</exclude>
</excludes>
</instrumentation>
<formats>
<format>xml</format>
<format>html</format>
</formats>
</configuration>
</plugin>
并通过以下命令开始测试:
mvn clean cobertura:cobertura
但如果其中一个单元测试失败,Cobertura 只会记录此信息,不会标记构建失败。
Tests run: 287, Failures: 1, Errors: 1, Skipped: 0
Flushing results...
Flushing results done
Cobertura: Loaded information on 139 classes.
Cobertura: Saved information on 139 classes.
[ERROR] There are test failures.
.................................
[INFO] BUILD SUCCESS
如何配置 Cobertura 在单元测试失败之一中标记构建失败?
提前致谢。
I've configured cobertura code coverage in my pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<instrumentation>
<excludes>
<exclude>**/*Exception.class</exclude>
</excludes>
</instrumentation>
<formats>
<format>xml</format>
<format>html</format>
</formats>
</configuration>
</plugin>
And start test by following command:
mvn clean cobertura:cobertura
But if one of unit test fail Cobertura only log this information and doesn't mark build fail.
Tests run: 287, Failures: 1, Errors: 1, Skipped: 0
Flushing results...
Flushing results done
Cobertura: Loaded information on 139 classes.
Cobertura: Saved information on 139 classes.
[ERROR] There are test failures.
.................................
[INFO] BUILD SUCCESS
How to configure Cobertura marks build failed in one of unit test fail?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您从 cobertura 插件运行特殊目标,则如果测试未成功通过,您将无法强制 Maven 使构建失败。插件目标将会成功。
您可以将 cobertura 运行绑定到生命周期阶段(例如测试)。这将使 cobertura 目标在此阶段运行(
mvn clean test
),并且如果该阶段失败则失败。该解决方案的缺点是 cobertura 目标将在每个
test
阶段运行。If you run a special goal from the cobertura plugin you can not force maven to fail the build if a test was not passed successfully. The plugin goal will succeed.
You can bind the cobertura run to a lifecycle phase (e.g. test). This will make the cobertura goal run with this phase (
mvn clean test
) and fail if this phase fails.The disadvantage of this solution is that the cobertura goal will run ich each
test
phase.您可以将
haltOnFailure
属性设置为 true。You could set
haltOnFailure
property to true.