Jacoco & Gradle Test Kit with Java

I have some functional tests with Gradle’s test kit, for a custom plugin. The tests work fine and IntelliJ reports 100% code coverage on it. When I put Jacoco into Gradle and run the same report it claims 0% code coverage on every @TaskAction I have. I have looked into forum posts and attempted to use the the plugin Jacoco TestKit Plugin, to no avail, I think I’m missing something. If anyone has used that plugin with Java and building a custom plugin any help would be great.

If you also know how to change the build.gradle.kts to make it work as well that would be great.

Thanks for any help provided.

Look at the build scripts for the asciidoctor-gradle-plugin how Jacoco is being used. test reports are being generated for each subproject on unit, integration and compatibility test level. The toplevel Jacoco task combines reports from every subproject. Hopefully you’ll find some inspiration in there.

Looks like my first issue about the code coverage was that an unit test was covering up the real issue. The bug/issue is https://github.com/koral--/jacoco-gradle-testkit-plugin/issues/17. I was using Gradle 6.5, down grading to 6.4.1 for now until the bug is fixed. Thanks for the link to the build script your using.

I’m still at a loss about how to test default dependencies and make them work for a Gradle plugin. I followed the steps but it always seems to use the default dependency version.

I looked at that plugin and remembered there was a bug in the kotlin DSL with testkit. Normally if you want code coverage with testkit you just have to run GradleRunner using withDebug(true). It fails for Kotlin DSL. I’m not sure if it has been resolved in the later version of Gradle. That is the reason why GradleTest also turns off debug mode when it sees a build,gradle.kts file in the test set.

BTW there is a cheap way of testing dependencies without resorting to TestKit. Set up a normal unit tests using ProjectBuilder instead. Call project.evaluate() and then do your assertions.

Yeah I was using ProjectBuilder as well, doing that caused the error message for jacoco-gradle-testkit-plugin to be hidden. I figured out the default dependencies issue, it is very important you use " in your dependencies when overriding the default version.

Thanks for your assistance.