JaCoCo & Kotlin: Coverage on Generated Code

written in coverage, generated, jacoco, kotlin

JaCoCo works flawlessly with Kotlin. Except when it reports lines not covered on generated code 😡. Fortunately there’s a fix already in place.


Update 08/26: JaCoCo 0.8.2 has now officially been released 👏 No need to use the 0.8.2-SNAPSHOT anymore.


What!? I didn’t even write those functions! There’s no way I’m writing tests for them. I’m pretty sure the compiler knows what it’s doing…

Me Every Time I Saw the Coverage Report

Good news is that this has been fixed in the latest JaCoCo release (thanks to goodwink). Bad news is that 0.8.2 is not out yet 😞

If you are like me, and can’t wait to get this working, you can use the SNAPSHOT version of JaCoCo making this changes on your build.gradle:

1
2
3
4
5
6
7
8
repositories {
  
  maven("https://oss.sonatype.org/content/repositories/snapshots")
}

jacoco {
  toolVersion = "0.8.2-SNAPSHOT"
}

(I’m using Gradle with Kotlin DSL in this example)

Now you can finally take your Kotlin coverage to 100% without having to write tests for component1() and component2().


Comments