[英]Jacoco Showing Wrong Coverage check Result
我已经通过maven在我的项目中配置了Jacoco插件。
这是我的jacoco配置
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<excludes>
</exclude>**/some/package/SomeClass*</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>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>CLASS</element>
<excludes>
<exclude>*Test</exclude>
</excludes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>80%</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
我已经执行了Test,并显示了抽象类的94%的覆盖率,我使用了它的具体实现对其进行了测试。
当我通过maven build运行时
我收到以下错误
类my.package.AbstractParser.1违反了规则:行覆盖率是0.00,但预期最小值是0.80
我尝试在Test上使用虚拟实现来测试抽象类,但仍然遇到相同的错误
有人可以告诉我我在做什么错。
编辑:我找出了失败的原因
我已经写了一个内联地图初始化
return new HashMap<String, String>() {
{
put(input, "");
}
};
相对于该部分,覆盖率显示为0%。 所以我的测试没有涵盖这部分。
可是我累了
final Map<String, String> defaultMap = new HashMap<>();
defaultMap.put(input, "");
return defaultMap;
构建过程甚至没有覆盖新代码。 有人可以解释一下为什么内联初始化会发生吗?
您的配置
<rules>
<rule>
<element>CLASS</element>
<excludes>
<exclude>*Test</exclude>
</excludes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>80%</minimum>
</limit>
</limits>
</rule>
</rules>
表示每个类别的线路覆盖率至少应为80%。
return new HashMap<String, String>() {
{
put(input, "");
}
};
声明匿名类 ,JaCoCo报告中可见什么是BTW-请参见下面的屏幕快照的第一表行
而
final Map<String, String> defaultMap = new HashMap<>();
defaultMap.put(input, "");
return defaultMap;
不声明任何类。
尝试将其添加到您的gradle构建中
android {
testOptions {
unitTests {
all {
jvmArgs '-noverify'
}
}
}
}
测试和覆盖率存在问题,因此您需要配置jvmArgs
设置以进行覆盖率检查,可以在IDE本身中启用它,但是在CI / maven /中运行覆盖率时,应在gradle中对其进行配置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.