Getting jacoco report from cucumber tests with gradle

天涯浪子 提交于 2020-04-30 07:47:48

问题


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:


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



来源:https://stackoverflow.com/questions/30851776/getting-jacoco-report-from-cucumber-tests-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!