[英]My Jacoco report is showing very little code coverage
我试图弄清楚我在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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.