gpt4 book ai didi

java - Maven Cobertura : unit test failed but build success

转载 作者:搜寻专家 更新时间:2023-11-01 03:13:07 27 4
gpt4 key购买 nike

我已经在我的 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 在单元测试失败之一中标记构建失败?

提前致谢。

最佳答案

如果您从 cobertura 插件运行一个特殊目标,如果测试未成功通过,您不能强制 maven 使构建失败。插件目标将会成功。

您可以将 cobertura 运行绑定(bind)到生命周期阶段(例如测试)。这将使 cobertura 目标在此阶段运行 (mvn clean test),如果此阶段失败则失败。

        <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<formats>
<format>xml</format>
<format>html</format>
</formats>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>

此解决方案的缺点是 cobertura 目标将在每个 test 阶段运行。

关于java - Maven Cobertura : unit test failed but build success,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5142254/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com