【问题标题】:Exclude folder in coverage JUnit [closed]在覆盖 JUnit 中排除文件夹 [关闭]
【发布时间】:2021-10-07 22:58:01
【问题描述】:

它试图解析这些文件夹,但我只需要它来检测主要和测试,并排除目标。

This is my actual coverage

我使用 JUnit、SonarQ、Maven 和 Jacoco。

我有很多 DTO 和其他我不想添加的类...

Jacoco 的插件:

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <configuration>
                    <excludes>
                        <exclude>**/target/generated-sources/xjc/*</exclude>
                    </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-report</id>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
         </plugin>

【问题讨论】:

    标签: java spring-boot junit5 spring-test jacoco


    【解决方案1】:

    仅报告目标,我假设您已经拥有exec 文件。您需要排除由xjc 生成的类,而不是文件夹,例如**/generated/**/*.class 其中generated 是子包名称之一。

    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.5</version>
        <executions>
            <execution>
                <id>report</id>
                <phase>verify</phase>
                <goals>
                    <goal>report</goal>
                </goals>
                <configuration>
                    <dataFile>${project.build.directory}/coverage-reports/aggregate.exec</dataFile>
                    <excludes>
                        <exclude>**/model/**/*.class</exclude>
                        <exclude>**/infrastructure/**/*.class</exclude>
                    </excludes>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

    • 对不起,我提供的信息不好,我已经更新了帖子,看看是否有更好的理解,非常感谢您的评论!
    • 这仍然适用,将您的configuration 部分移动到报告目标的execution,再次 - 您正在排除文件夹,您需要排除类。 **/your/package/in/xjc/folder/**/*.class
    • 爱你,谢谢
    猜你喜欢
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-20
    • 2018-12-04
    相关资源
    最近更新 更多