gpt4 book ai didi

java - 我的 Jacoco 报告显示代码覆盖率非常低

转载 作者:行者123 更新时间:2023-12-02 01:45:13 28 4
gpt4 key购买 nike

我试图了解 Scala 中的一些单元测试和 Java 中的源代码(测试和代码位于不同的包中)的代码覆盖率。当我运行 Jacoco 报告时,它仅显示 4% 的代码覆盖率。

当我查看报告时,它显示我为其创建测试的许多文件的百分比为 0。我怀疑单元测试未包含在报告中,可能是因为所有测试类文件都位于 target/test-classes 目录中。我尝试过包含 includeTests 标记,但没有任何效果。

以下是该插件在 pom 中的样子:

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<configuration>
<includeTests>true</includeTests>
<!--<includes>
<include>**/test-classes/**</include>
</includes>-->
<excludes>
<exclude>**/dto/**</exclude>
<exclude>**/exceptions/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

现在我已经注释掉了 include 标签,因为如果我包含它,测试将使用 0 个类进行编译。我还能如何包含 target/test-classes 目录?

抱歉,如果这是一个简单的修复,我对单元测试和 Jacoco 非常陌生。谢谢!

最佳答案

这是我个人的设置。这有点困惑,我仍在研究其中的某些部分,但它对我有用。你可以试试这个。

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.20</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>

关于java - 我的 Jacoco 报告显示代码覆盖率非常低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57463971/

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