gpt4 book ai didi

unit-testing - Jacoco 检查与 jacoco 报告中的不同覆盖率值

转载 作者:行者123 更新时间:2023-11-28 21:16:14 24 4
gpt4 key购买 nike

我在我的项目中设置了 Jacoco 来执行 a) 检查代码覆盖率和 b) 生成覆盖率报告。生成的 HTML 报告显示了正确的覆盖率值,但 Jacoco 检查在构建过程结束时生成的警告消息显示了不同的错误值。我想知道我在这里做错了什么。

例如,我可以在生成的 HTML 报告中看到一个 util 类:

jacoco report

但是对于同一个类,我在构建完成时看到了这个:

jacoco check warning

这是我的 pom.xml 文件中的 jacoco-report 配置:

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco.check</id>
<goals>
<goal>check</goal>
</goals>
<phase>${jacoco.check.phase}</phase>
<configuration>
<skip>${jacoco.skip}</skip>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>CLASS</element>
<excludes>
<exclude>com/xxxxxx/**/config/**/*</exclude>
<exclude>com/xxxxxx/**/filter/**/*</exclude>
<exclude>com/xxxxxx/xxxxxx/errors/*</exclude>
<exclude>com/xxxxxx/xxxxxx/security/*</exclude>
<exclude>com/xxxxxx/xxxxxx/xxxxxxOnlineWebApplication.class</exclude>
</excludes>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.90</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>

<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<propertyName>itCoverageAgent</propertyName>
</configuration>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

我的 jacoco-check 配置如下:

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>agent-for-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.reportPaths}</destFile>
</configuration>
</execution>
<!-- Integration-tests executed with failsafe-plugin -->
<execution>
<id>agent-for-it</id>
<phase>package</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.itReportPath}</destFile>
</configuration>
</execution>
</executions>
<configuration>
<excludes>
<exclude>com/xxxxxx/**/config/**/*</exclude>
<exclude>com/xxxxxx/**/filter/**/*</exclude>
<exclude>com/xxxxxx/xxxxxx/errors/*</exclude>
<exclude>com/xxxxxx/xxxxxx/security/*</exclude>
<exclude>com/xxxxxx/xxxxxx/xxxxxxOnlineWebApplication.class</exclude>
</excludes>
</configuration>
</plugin>

最佳答案

看起来您正在更改存储结果的位置:

<destFile>${sonar.jacoco.itReportPath}</destFile>

您还需要使用 <dataFile> 告诉检查插件在哪里可以找到数据文件。项目添加到您的规则配置中。

请参阅jacoco:check docs获取更多信息。

关于unit-testing - Jacoco 检查与 jacoco 报告中的不同覆盖率值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57903852/

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