16

使用该选项cobertura-maven-plugin可以将 setter 和 getter 排除在代码覆盖范围之外。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>
4

3 回答 3

13

官方不支持,见评论:

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

提到的解决方案:

很久没有打开这个问题了。这是一个非常有趣的功能。例如,它在 clover 和 corbetura 中实现。有实现过滤的fork : github.com/huangxiwei/jacoco , https://github.com/mchr3k/jacoco从年初开始。你为什么不把那些 fork 合并到 master 分支中呢?即使在开始时没有实现所有过滤,所需的主要过滤器也会在您编写的 wiki 页面中列出(尝试使用资源、同步块、枚举静态方法)。覆盖率是一个非常有用的工具,它越多,它就越有用。当覆盖率达到高值时,它有很大帮助,它有助于专注于正确的课程。

于 2014-10-21T10:40:04.530 回答
13

从 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

注解会@Generated被添加到setter/getter等中,在覆盖分析中会被跳过。

于 2020-05-15T07:59:21.857 回答
-7

我推荐使用 Cobertura,它没有这样的限制,也没有太多的误报警告。

于 2016-01-04T22:08:51.593 回答