0

Jacoco fails to generate a code coverage report if the tests fail.

Below is the relevant section of my gradle file:

task unitTest(type: Test) {
    forkEvery = 1
    jvmArgs = ['-Djava.net.preferIPv4Stack=true']
    testClassesDir = sourceSets.unitTest.output.classesDir
    classpath = sourceSets.unitTest.runtimeClasspath
    exclude '**/**TestBase.*'
    outputs.upToDateWhen { false }
    ignoreFailures = true
    finalizedBy jacocoTestReport
}

task functionalTest(type: Test) {
    forkEvery = 1
    jvmArgs = ['-Djava.net.preferIPv4Stack=true']
    testClassesDir = sourceSets.functionalTest.output.classesDir
    classpath = sourceSets.functionalTest.runtimeClasspath
    exclude '**/**TestBase.*'
    outputs.upToDateWhen { false }  
}


jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."

    additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "${buildDir}/reports/jacoco/html"
    }   
    executionData = files('build/jacoco/test.exec')
}

Even though I have specified the "ignoreFailures=true", there is no code coverage report after the test run.

There were failing tests. See the report at: file:///unitTest/index.html
:MYModule:jacocoTestReport SKIPPED

BUILD SUCCESSFUL

Total time: 41 mins 34.018 secs

1 Answer 1

1

The issue was that the executionData was pointing to a wrong "test.exec". It should have been "unitTest.exec", named after the test task that was being executed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.