We have implemented Integration tests for gradle plugins using Testkit. I am looking to get the code coverage reports for these Integration tests using Jacoco.
I have addded Jacoco plugin , but that doesn’t seems to generate the proper report, it always shows 0% code covered.
Do anyone have suggestion on how to get the code coverage report of the plugin integration tests that are developed using Testkit ?
Tests executed with the TestKit are run in a daemon JVM. You’ll need to tell the daemon JVM to set the Java agent argument. Something like this should do:
You can set the daemon JVM parameter on the command line via system property org.gradle.jvmargs. These JVM arguments are propagated to the daemon JVM. The drawback to this approach is that you’ll have to remember to set it every time you run the build.
Alternatively, you could use the internal GradleRunner method withJvmArguments(String...). Keep in mind that the method might change with future versions of Gradle.
GradleRunner.create().withJvmArguments(...)
Please note that we are planning to support Jacoco for TestKit out-of-the-box with milestone 3.
I tried also both, adding a gradle.properties or using .withJvmArguments(…) but both approached didn’t forward the arguments correctly to testkit. Is it possible that something is missing at the moment?
I did get this to work, to ensure i always had the correct jacoco runtime available i added a configuration with the dependency and then wrote the correct org.gradle.jvmargs to the gradle.properties file before then running the build: