How to get test coverage or ignore by Jacoco for Kotlin data classes

tse picture tse · Jan 23, 2018 · Viewed 8.3k times · Source

Jacoco shows 0% coverage for Kotlin's data classes. How to configure it to measure coverage or ignore data classes at all?

Answer

Arpit Rastogi picture Arpit Rastogi · Sep 2, 2018

I was looking for the solution for same test coverage issue with auto-generated code for data model classes and stumbled upon following :
Kotlin + JaCoCo: Tuning Compiler to Skip Generated Code

Solution: Update JaCoCo plugin to 0.8.2 and your issues is resolved.

JaCoCo has solved this very issue in 0.8.2 release, please read the changelog-

  • Classes and methods annotated with runtime visible and invisible annotation whose simple name is Generated are filtered out during generation of report (GitHub #731).
  • Methods added by the Kotlin compiler that do not have line numbers are filtered out during generation of report. Idea and implementation by Nikolay Krasko (GitHub #689).