从 Jacoco 覆盖率报告中排除生成的 Hibernate 方法

问题描述 投票:0回答:1

我想从 Jacoco 代码覆盖率报告中排除 Hibernate 生成的方法。

例如,应排除图像中的

$$_hibernate_*
方法。

我知道要按方法排除该方法,可以使用包含字符串

Generated
的注释进行注释,如 this 答案 中所述,但我不确定如何将这样的注释应用于 Hibernate方法。也许我应该如何使用 Hibernate Metamodel Generator

hibernate jacoco
1个回答
0
投票

您可以使用构建工具(例如 Maven 或 Gradle)中的排除配置选项来指定应从覆盖率分析中排除哪些类或方法。

以下是在 Maven 的 pom.xml 中执行此操作的方法:

<build>
<plugins>
    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <configuration>
            <excludes>
                <exclude>**/*$$_hibernate_*</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>
        </executions>
    </plugin>
</plugins>
  • <exclude>**/*$$_hibernate_*</exclude>
    指定任何方法或 包含
    $$_hibernate_
    的类名应排除在覆盖范围之外 分析。
© www.soinside.com 2019 - 2024. All rights reserved.