Gradle plugins integration tests code coverage with Jacoco plugin

(arv) #1

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 ?

(Benjamin Muschko) #2

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.


Please note that we are planning to support Jacoco for TestKit out-of-the-box with milestone 3.

(Luke Daley) #3

You can also do this by writing a at the root of your build under test with:

org.gradle.jvmargs=«agent args»

(arv) #4

Thank you for quick response , I will try your suggestions and let you know.

(Iain Adams) #5

Were you able to get this to work, i have tried with the approach , adding to the test task jvmArgs but still no joy :frowning:

(Thomas Pohl) #6

I tried also both, adding a 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 am using gradle 2.13 at the moment.

(Iain Adams) #7

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 file before then running the build:

./gradlew setupJacocoProps
./gradlew integTest


configurations {

dependencies {
jacocoRuntime “org.jacoco:org.jacoco.agent:${jacoco.toolVersion}:runtime”

task setupJacocoProps << {

Hope this helps.

Testkit Jacoco Coverage
(Thomas Pohl) #8

Thanks for the answer! But to me it looks like you use this for your normal build…

Or did you run this with testkit, setting the build up with:

For the normal build this works for me, too. But the GradleRunner ignores my additional jvm properties.

(Iain Adams) #9

Im not passing anything to my integration tests, just creating the, running the tests, then generating the reports(html/xml etc).

Do you have a project on github i can look at might be able to see whats happening.

(Lance Java) #10

FYI - I had to tweak this solution slightly for windows as backslashes were causing it to fail
More info at Testkit Jacoco Coverage