How do you do it? Testing, integration testing and code coverage

My goal is to setup a build pipeline as discussed in this movie, and I have been messing about with the first steps.

I have a project with some junit tests (reading/writing xml and stuff like that) and have moved my database tests to an integration test task.

However I am not trying to add Jacoco and have only found ways to run it on either test or integTest task. Is there a way to run it on both or is this not supposed to be used this way?

Currently my script looks like this:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'jacoco'

sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'
repositories {

configurations {
    integrationTestCompile.extendsFrom testCompile
    integrationTestRuntime.extendsFrom testRuntime

jacoco {
    toolVersion = ""
    reportsDir = file("$buildDir/customJacocoReportDir")

jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "${buildDir}/jacocoHtml"

dependencies {
	compile 'org.apache.poi:poi-ooxml:3.9'
        compile 'javax.mail:mail:1.4.1'
	compile fileTree(dir: 'libs', include: ['sqljdbc4.jar'])
	integrationTestCompile 'junit:junit:4.12'
	testCompile 'junit:junit:4.12'

jar {
    manifest {
            attributes 'Implementation-Title': 'Helper Classes',
           'Implementation-Version': version

sourceSets {
    integrationTest {
        java {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/integTest/java')
        resources.srcDir file('src/integTest/resources')

task integrationTest(type: Test){
	description = 'Run the integration tests.'
	group = 'verification'
	testClassesDir = sourceSets.integrationTest.output.classesDir
	classpath = sourceSets.integrationTest.runtimeClasspath

task jacocoIntegrationTestReport(type: JacocoReport){
	sourceSets sourceSets.main
	executionData integrationTest
1 Like

I’m also interested in this. I asked a similar question but didn’t get a response

I agree! Source code of the “todo” example project would be a great help to get started with all the gradle scripts and plugins!

Both sourceSets and executionData appear to allow multiple values. Have you tried:

task jacocoReport(type: JacocoReport){
    sourceSets sourceSets.main
    executionData test, integrationTest

Assuming that’s what you mean by running both. I’m interpreting that as you want to effectively have the union of the test and integrationTest coverage in a single report.

BTW, untested and just based on the documentation/scan of plugin code.

I have done before integration testing by adding an extra source set and duplicating the all test-related tasks, but these days I just have a separate “integration-testing” module (or more than one, nested under heir projects). I find this cleaner and causes less headaches as you don’t need to do anything special.

The cost is that it complicates the directory structure, but I find myself much searching for classes. When I need to browse classes, I switch to IDEA’s package view anyway.

For coverage, I use Teamcity - it does a good job at injecting the coverage plugin and aggregating the metrics. Again, the driving reason is to simplify the build process.

Thx pledbrook, this did the trick for me. I had tried supplying an array [bla,bla] but that gave errors. Never thought of using it without the brackets!

1 Like

Maybe you find the nebula.integtest plugin useful for. It does all the wiring for you.