简体   繁体   English

Jacoco 排除类

[英]Jacoco exclude classes

Hi I am trying to exclude classes for my code coverage using jacoco.嗨,我正在尝试使用 jacoco 为我的代码覆盖率排除类。 I want to exclude the gui folder and all the classes inside it.我想排除 gui 文件夹及其中的所有类。

   <configuration>
      <excludes>
          <exclude>com.project/folder/tools/gui/*.class</exclude>
      </excludes>
      </configuration>

com.project -> folder -> tools -> gui com.project -> 文件夹 -> 工具 -> gui

I have tried many different paths but for some reason it wont exclude any of them.我尝试了许多不同的路径,但出于某种原因,它不会排除其中任何一条。 Am I doing this wrong?我这样做错了吗? Can anyone point me in the right direction.任何人都可以指出我正确的方向。

I have also faced the same problem.In my case ,I was trying to generate code coverage of a application which was running on j2EE server.我也遇到了同样的问题。就我而言,我试图生成在 j2EE 服务器上运行的应用程序的代码覆盖率。 I have tried to remove some classes which were not getting used much , to increase code coverage, but exclude does not worked for me.我试图删除一些不太常用的类,以增加代码覆盖率,但 exclude 对我不起作用。

At last i have tried work around for this instead of using exclude in to configuration.最后,我尝试解决此问题,而不是在配置中使用排除。 I have removed the clasess from the path of the task that was responsible for generating report.我已从负责生成报告的任务路径中删除了该类。

Maven include/exclude syntax is Ant. Maven 包含/排除语法是 Ant。 So I suggest you to have a look on fileset documentation , where you can find few illustrative examples.所以我建议你查看文件集文档,在那里你可以找到一些说明性的例子。

In your particular configuration, it could work this pattern在您的特定配置中,它可以使用这种模式

**/gui/**

assuming that you don't use the package name "gui" in other context.假设您不在其他上下文中使用包名称“gui”。

We can exclude the class from coverage checking (ie fail the build if the coverage doesn't meet the target), but not exclude them from the reporting (ie you can still see the class in the report).我们可以从覆盖率检查中排除该类(即如果覆盖率不符合目标则构建失败),但不能将它们从报告中排除(即您仍然可以在报告中看到该类)。 Is it what you after?是你追求的吗?

If you would like to exclude the classes from checking, you could try the following config, and please use com.project.folder.tools.gui.* pattern without the slash and trailing suffix.如果您想从检查中排除类,您可以尝试以下配置,请使用 com.project.folder.tools.gui.* 模式,不带斜杠和尾随后缀。

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>check</id>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
            <haltOnFailure>true</haltOnFailure>
            <rules>
                <rule>
                    <element>CLASS</element>
                    <excludes>
                        <exclude>com.example.className</exclude>
                        <exclude>com.example.config.*</exclude>
                    </excludes>
                    <limits>
                        <limit>
                            <counter>LINE</counter>
                            <value>COVEREDRATIO</value>
                            <minimum>0.80</minimum>
                        </limit>
                    </limits>
                </rule>
            </rules>
            </configuration>
         </execution>
     </executions>
 </plugin>

Check this offical doco for detail查看此官方文档以了解详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM