我检查了Jacoco和浏览了几个堆栈溢出问题。结果显示,不支持注解的jacoco过滤方法的0.7.9版本,只支持整个类。现在发布了0.8.0和0.8.1。这些版本中添加了这个特性吗?我查了雅科的变更记录。
https://github.com/jacoco/jacoco/releases
但是,在最新版本中看不到任何与过滤相关的内容。但还想确认一下是否有人已经做到了这一点,是如何做到的?
发布于 2019-04-14 06:54:11
我找到了如何从覆盖率报告中排除静态方法的解决方案。
示例java代码:
private static class Document {
private static org.w3c.dom.Document createDocument() {
try {
final javax.xml.parsers.DocumentBuilderFactory factory =
javax.xml.parsers.DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
final javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
return builder.newDocument();
} catch (javax.xml.parsers.ParserConfigurationException ex) {
return null;
}
}
}示例排除配置:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/Xml$Document.class</exclude>
</excludes>
</configuration>
</plugin>https://stackoverflow.com/questions/50442279
复制相似问题