简体   繁体   English

从 JaCoCo 测试覆盖范围中排除 Kotlin 个数据类

[英]Exclude Kotlin data classes from JaCoCo test coverage

I have the latest version of JaCoCo with Gradle(the latest version).我有最新版本的 JaCoCo 和 Gradle(最新版本)。 How can I exclude data classes from test coverage?如何从测试范围中排除数据类?

Starting from JaCoCo v0.8.2, you can exclude classes and methods by using a Generated annotation, JaCoCo will ignore them.从 JaCoCo v0.8.2 开始,您可以使用Generated注解排除类和方法,JaCoCo 将忽略它们。

@ExcludeGenerated
data class User(val id: Int)

class Something {
    @ExcludeGenerated
    fun ignoreMe() { }
}
@Retention(AnnotationRetention.RUNTIME)
@Target(
    AnnotationTarget.CLASS,
    AnnotationTarget.FUNCTION,
    AnnotationTarget.PROPERTY_GETTER,
    AnnotationTarget.PROPERTY_SETTER,
    AnnotationTarget.CONSTRUCTOR
)
annotation class ExcludeGenerated

https://github.com/jacoco/jacoco/releases/tag/v0.8.2 https://github.com/jacoco/jacoco/releases/tag/v0.8.2

Classes and methods annotated with annotation whose retention policy is runtime or class and whose simple name is Generated are filtered out during generation of report (GitHub #731).使用 annotation 注释的类和方法,其保留策略为 runtime 或 class 并且其简单名称为 Generated 在生成报告期间被过滤掉 (GitHub #731)。

In case you are using gradle config:如果您使用 gradle 配置:

jacocoTestReport {
    dependsOn test // tests are required to run before generating the report
    
    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it, exclude: [
                "com/abcd/models/**/DataModel.class",
                "com/abcd/models/**/*Dto.*",
                "**/models/*"
            ])
        }))
    }
}

Refer the following for more context:有关更多上下文,请参阅以下内容:
https://www.baeldung.com/jacoco-report-exclude https://www.baeldung.com/jacoco-report-exclude

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

相关问题 无法从 kotlin jacoco 测试覆盖率中排除生成的类 - Unable to Exclude generated classes from kotlin jacoco test coverage 如何获得测试覆盖或忽略Jacoco的Kotlin数据类 - How to get test coverage or ignore by Jacoco for Kotlin data classes Intellij,JaCoCo负责Kotlin的报道 - Intellij, JaCoCo for Kotlin coverage "Jacoco 在 Android 项目中通过单元测试报告 Kotlin 类的覆盖率为 0" - Jacoco is reporting 0 coverage of Kotlin classes by unit tests, in an Android project 声纳 Jacoco 未在覆盖范围内考虑 Kotlin androidTest(集成测试用例) - Sonar Jacoco not considering Kotlin androidTest (integration test case) in coverage 使用 jacoco 和 gradle 从多模块项目的覆盖范围中排除 - Exclude from coverage on multimodule project using jacoco and gradle Jacoco覆盖范围和Kotlin默认参数 - Jacoco coverage and Kotlin default parameters Jacoco 在 Kotlin 和 Java Z402C5D9AF6B43711EAZ070 项目测试中找不到 Kotlin 文件覆盖率 - Jacoco doesn't find Kotlin files coverage in Kotlin and Java maven project from kotlin's tests 如何排除 Kotlin 中测试类的显式 Api 警告? - How to exclude explicitApi warnings for test classes in Kotlin? Kotlin JaCoCo,无覆盖 -> IllegalClassFormatException ...请提供原始的非仪器类 - Kotlin JaCoCo, no coverage -> IllegalClassFormatException ... Please supply original non-instrumented classes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM