Search code examples
gradlecode-coveragejacoco

Gradle execute JUnit TestSuite with JacocoTestReport


I'm using a TestSuite to handle a DB connection that spans across multiple test classes. These tests all pass when executed as a stand alone TestSuite. However, when executed over Gradle each individual test class is executed instead of the TestSuite.

How can I tell Gradle to skip the individual test classes and include the TestSuite instead?

This is what I have now

jacoco {
    toolVersion = "0.7.9"
    reportsDir = file("jacoco")
}

// run with [test jacocoTestReport] 
jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination file("jacoco/jacocoHtml")
    }

    afterEvaluate {
        classDirectories = files(classDirectories.files.collect {
            fileTree(dir: it, exclude: ['some_excluded_package/**'])
        })
    }
}

What I have tried:

test {
    filter {
        include 'xxx/MasterSuite'
        exclude '**/*ExcludeFromGradle.class'
    }

    jacoco {
        jacocoTestReport {
            [..]

//====================
// Also tried this

test {
    filter {
        includeTestsMatching "*MasterSuite"
    }
}

And a few more variations of similar design using JaCocoTaskExtension that didn't compile properly due to my lack of understanding.

Now. How can I adapt this to include my 'Mastersuite' TestSuite and exclude the 'ExcludeFromGradle' classes?


Solution

  • Is your suite located under src/test/java?

    Have you tried?

    test {
        include '**/MasterSuite.class'
    }