在JaCoCo代码覆盖范围中排除Setter和Getters

Ben*_*uer 8 getter setter code-coverage jacoco jacoco-maven-plugin

随着cobertura-maven-plugingetter和setter方法可排除使用代码覆盖ignoreTrivial选项.是否还有这种可能性jacoco-maven-plugin

这是我目前的配置:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.7.1.201405082137</version>
  <configuration>
    <excludes>
      <exclude>com/welovecoding/web/blog/test/**/*.class</exclude>
    </excludes>
  </configuration>
  <executions>
    <execution>
      <id>amend-unit-test-java-agent-option</id>
      <goals>
        <goal>prepare-agent</goal>
      </goals>
    </execution>
    <execution>
      <id>report</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

小智 10

官方不支持,请参阅以下评论:

https://github.com/jacoco/jacoco/issues/15

提到的方案:

这个问题打开已经很久了.这是一个非常有趣的功能.例如,它是在三叶草和corbetura中实现的.有迹象表明,实现过滤叉:github.com/huangxiwei/jacoco, https://github.com/mchr3k/jacoco自今年的开头.为什么不将这些fork合并到master分支中?即使在开始时未实现所有过滤,所需的主过滤器也会列在您编写的Wiki页面中(尝试使用资源,同步块,枚举静态方法).覆盖范围是一个非常有用的工具,更多的是它会产生更多有用的工具.当覆盖率达到很高时,它有助于重点关注正确的类.


pot*_*ame 10

从 JaCoCo 0.8.0 开始,由于过滤选项,可以从覆盖率指标中排除Lombok自动生成的 getter / setter(以及toString(), equals(), ...):

龙目岛

用@lombok.Generated 注释的方法(由 Lombok getter、setter、equals、hashcode、toString 等生成)- 在 0.8.0 中完成

为此,您首先需要lombok.config在项目的根文件夹中创建一个文件,其中包含以下内容:

lombok.addLombokGeneratedAnnotation = true
Run Code Online (Sandbox Code Playgroud)

@Generated注释将被添加到制定者/吸气等,将在覆盖分析被跳过。