Krivers
Krivers

Reputation: 59

jacocoTestReport always SKIPPED

Expected Behavior

jacocoTestReport work

Current Behavior

jacocoTestReport SKIPPED

Context

I created a task whose type is Test, and jacocoTestReport depends on the task. When I ran the task, jacocoTestReport did not work and I got the following information

jacocoTestReport SKIPPED

I find if I use the task test directly, jacocoTestReport worked fine. It makes me confused

the following code caused the above issue

plugins {
    id 'java'
    id 'jacoco'
}

repositories {
    mavenCentral()
}

dependencies {

}

task myTest(type: Test) {
    useTestNG()
    useJUnitPlatform()

    finalizedBy jacocoTestReport
    reports {
        junitXml.required = false
        html.required = true
    }
    jacoco {
        enabled = true
        destinationFile = layout.buildDirectory.file("jacoco/${name}.exec").get().asFile
    }
}

jacocoTestReport {
    // tests are required to run before generating the report
    dependsOn myTest
    reports {
        xml.required = false
        csv.required = false
        html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
    }

}

Steps to Reproduce

example project

Your Environment Gradle 7.1.1

Upvotes: 3

Views: 11321

Answers (2)

s00103898-276165-15433
s00103898-276165-15433

Reputation: 988

I get the same issue. I post what I found here and hope it will be helpful for somebody with the same issue.

  • config: I am using groovy with gradle and spock testing.
  • issue: When running test, I have only one jacoco empty folder generated and have no test reports.
  • I run the following script to trace the information.
 ./gradlew clean build jacocoTestReport  --i
  • And I find that "jacocoTestReport SKIPPED". Why it's skipped?
> Task :lib:jacocoTestReport SKIPPED
Skipping task ':lib:jacocoTestReport' as task onlyIf is false.
:lib:jacocoTestReport (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:lib:check (Thread[Execution worker for ':',5,main]) started.
  • root cause:

    • Jacoco uses the JUnit platform to generate code coverage reports, even when running Spock tests. If Jacoco didn't set the JunitPlatform and the test report cannot be generated.
  • solution

    • add useJUnitPlatform() to test {}
test {
    useJUnitPlatform()
    finalizedBy jacocoTestReport // report is always generated after tests run
}

jacocoTestReport {
    dependsOn test // tests are required to run before generating the report
    reports {
        xml.enabled false
        csv.enabled false
        html.enabled true
        html.destination file("${buildDir}/jacocoHtml")
    }
}
  • run test and generate test report after test
 ./gradlew test

Upvotes: 1

Krivers
Krivers

Reputation: 59

It is expected, not an issue. just because I use the jacocoTestReport in a wrong way

see https://github.com/gradle/gradle/issues/18271

Upvotes: 0

Related Questions