Search code examples
gradlejacocowildfly-9

How to generate jacoco coverage in manual tests?


I have a web application running on wildfly 9 using gradle to build it, and I would like to get code coverage of manual tests, so I started using jacoco for doing so. What I have so far is this in my build.gradle file is this for starting java in debug mode:

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
    options.debug = true
    options.compilerArgs = ["-g"]
}

And this for defining jacoco reports

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

However, it does not generate jacoco folder, I think I am missing some point or something.


Solution

  • Usage of JaCoCo involves following steps:

    • execution of instrumented code (no matter as manual or automated tests)
    • generation of report

    Information that you provide in the question - is about compilation of Java files and generation of report, but nothing about execution of JVM.

    There are many ways to execute code with on-the-fly instrumentation depending on how JVM is started (Gradle/Maven/Ant plugins, etc.), but they all boil down to usage of JaCoCo Java Agent while starting JVM:

    java -javaagent:jacocoagent.jar ...