https://kotlinlang.org logo
Title
d

Davio

10/17/2018, 4:41 AM
Is there a good way to get code coverage for Kotlin with something like JaCoCo? If I just add the source and build dirs, wouldn't it just report false positives due to code generation for e.g. data classes?
g

gildor

10/17/2018, 5:54 AM
There are some Kotlin specific improvements in latest Jacoco versions, that cover data classes and some other cases
d

Davio

10/17/2018, 10:26 AM
I got JaCoCo to report coverage in its report, but still having trouble to pass it on to SonarQube, sadly
g

gildor

10/17/2018, 10:26 AM
Why? Jacoco report should be standard
maybe some problems with rendering on SonarQube?
because some cloud services that I used for coverage reports works properly with Kotlin code and jacoco reports
d

Davio

10/17/2018, 10:27 AM
I keep getting Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
g

gildor

10/17/2018, 10:29 AM
Not sure what you mean. I got reports from unit tests coverage and it was with debug. But I didn’t use sonar qube
d

Davio

10/17/2018, 10:31 AM
Well, I can get a very nice Jacoco html report with coverage, so that is working nicely
But somehow SonarQube is not understanding the jacoco test.exec or something
g

gildor

10/17/2018, 10:32 AM
For example this is coverage of one of my projects https://codecov.io/gh/gildor/kotlin-coroutines-retrofit
so yeah. probably there is some issue of SonarQube
d

Davio

10/17/2018, 10:33 AM
Yeah, it pointed to a stray java file (package-info.java) I had, so maybe there's only an issue with that
As there is no package-info.kts or something like that and I wanted some javadoc on that level, I just added that file
Maybe it confuses Sonar to have that file
I removed it and the warning is gone, but still no coverage in my sonarqube dashboard
I'm still stumped, it looks like I've set up everything correctly, but the Sonar gradle plugin just doesn't trigger its JaCoCo report collector even though I applied the jacoco plugin and a test.exec is generated. Maybe it has to do with using the Kotlin DSL for Gradle. I've looked at sonar logging and all paths point correctly, tried adding system properties such as sonar.java.coverage=jacoco, we have the Kotlin plugin on our sonarqube server, but no luck.