1

I have the latest version of JaCoCo with Gradle(the latest version). How can I exclude data classes from test coverage?

Darkin Rall
  • 377
  • 1
  • 4
  • 17

1 Answers1

2

Starting from JaCoCo v0.8.2, you can exclude classes and methods by using a Generated annotation, JaCoCo will ignore them.

@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

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).

ocos
  • 1,901
  • 1
  • 10
  • 12