Gradle plugins integration tests code coverage with Jacoco plugin

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 ?

1 Like

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:

-javaagent:/Users/bmuschko/org.jacoco.agent-0.7.1.201405082137-runtime.jar=destfile=/Users/bmuschko/dev/projects/myproj/build/jacoco/testKit.exec

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.

1 Like

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

org.gradle.jvmargs=«agent args»
1 Like

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

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

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 am using gradle 2.13 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:

./gradlew setupJacocoProps
./gradlew integTest

etc

configurations {
jacocoRuntime
}

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

task setupJacocoProps << {
file(‘gradle.properties’).write(“org.gradle.jvmargs:-javaagent:${configurations.jacocoRuntime.asPath}=destfile=$buildDir/jacoco/testKit.exec”)
}

Hope this helps.

1 Like

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:
GradleRunner.create().withJvmArguments(…)?

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

Im not passing anything to my integration tests, just creating the gradle.properties, 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.

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

1 Like

This thread is related to Jacoco & Gradle Test Kit with Java - #14 by PantherDD and applies similar solution as listed here.