1

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.

Rogger Fernandes
  • 805
  • 4
  • 14
  • 28

3 Answers3

2

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 ...
Godin
  • 9,801
  • 2
  • 39
  • 76
0

By default, the jacocoTestReport task is not wired into the DAG for a normal build. To run it you can call the following from command line

./gradlew test jacocoTestReport

If you want it to run every time the tests run (which I don't recommend) then you can wire it onto the DAG in your build.gradle

test.finalizedBy 'jacocoTestReport' // not perfect since it will run when test fails

Or perhaps

check.dependsOn 'jacocoTestReport' // 'build' task calls 'check' which calls 'test'
lance-java
  • 25,497
  • 4
  • 59
  • 101
0

Here's the article to set up jacoco java agent for backend code (for manual and integration): http://sdetsforsdets.com/2018/03/19/code-coverage-jacoco/

learner
  • 786
  • 7
  • 17