Getting jacoco report from cucumber tests with gradle

4.5k views Asked by At

I am working with gradle in a java project, I run my cucumber tests with a gradle task, something like this:

task cucumber (){
//task that starts the app
dependsOn 'jettyRunDaemon'
 jvmArgs '-javaagent:E:/MyProject/build/jacoco/jacocoagent.jar=destfile=build/jacoco/jacoco.cucumber.exec'
doLast {
    javaexec {
        main = 'cucumber.api.cli.Main'
        classpath = sourceSets.main.output +
                    sourceSets.test.output +
                    configurations.testRuntime
        args = cucumberArgs()
    }
}
}

List<String> cucumberArgs() {
def args = [
    '--format', 'junit:build/cucumber-reports/junit/report.xml',
    '--format', 'html:build/reports/cucumber',
    '-f', 'pretty',
    '--glue', 'com.company.packageWithGlueJavaCode']

// Feature locations
args.add('src/test/resources/features')

return args
}

Does anybody knows if there is someway to get a Jacoco code coverage report of my cucumber tests by configuring gradle?. I know that for JUnit (test task) jacoco automaticly creates a exec file in jacoco/*.exec and I can get a report from it... but is there someway I can get, let's say a cucumber.exec file to get a report from it??

1

There are 1 answers

2
Robert Halter On BEST ANSWER

Just add a JaCoCo Agent jar with this jvm Argument

-javaagent:[yourpath/]jacocoagent.jar=[option1]=[value1],[option2]=[value2]

to generate the .exec file.

Report Generation

Based on the collected *.exec files reports can be created the same way as for execution data collected with the Java agent. Note that for report generation the original class files have to be supplied, not the instrumented copies.

See http://www.eclemma.org/jacoco/trunk/doc/agent.html