[英]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.