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