简体   繁体   English

如何使用 gradle 获取空手道测试功能文件的 Jacoco 报告

[英]How to get Jacoco reports for the Karate test feature files using gradle

How to get Jacoco reports for the Karate test feature files using Gradle.如何使用 Gradle 获取空手道测试功能文件的 Jacoco 报告。

My project is a Gradle project and I am trying to integrate jacoco report feature in my project for the karate tests.我的项目是一个 Gradle 项目,我正在尝试将 jacoco 报告功能集成到我的空手道测试项目中。 The server is running in my local on 8080 port.服务器在我本地的 8080 端口上运行。

I am doing the following way to generate jacoco report and please let me know is my approach correct and also give me a solution to get the jacoco report for the gradle project.我正在通过以下方式生成 jacoco 报告,请让我知道我的方法是否正确,并给我一个解决方案来获取 gradle 项目的 jacoco 报告。

1) First I am trying to generate jacoco execution data with the help of jacocoagent.jar as follows with a Gradle task: 1)首先,我尝试在 jacocoagent.jar 的帮助下生成 jacoco 执行数据,如下所示,使用 Gradle 任务:

java -javaagent:/pathtojacocojar/jacocoagent.jar=destfile=/pathtojocofile/jacoco.exec -jar my-app.jar

2) Next, I am running a Gradle task to generate the report 2)接下来,我正在运行一个 Gradle 任务来生成报告

project.task ('jacocoAPIReport',type: org.gradle.testing.jacoco.tasks.JacocoReport) {
    additionalSourceDirs = files(project.sourceSets.main.allSource.srcDirs)
    sourceDirectories = files(project.sourceSets.main.allSource.srcDirs)
    classDirectories = files(project.sourceSets.main.output)
    executionData = fileTree(dir: project.projectDir, includes: ["**/*.exec", "**/*.ec"])
    reports {
        html.enabled = true
        xml.enabled = true
        csv.enabled = false
    }
    onlyIf = {
        true
    }
    doFirst {
        executionData = files(executionData.findAll {
            it.exists()
        })
    }
}

          project.task('apiTest', type: Test) {
                    description = 'Runs the api tests'
                    group = 'verification'
                    testClassesDirs = project.sourceSets.apiTest.output.classesDirs
                    classpath = 
                   project.sourceSets.apiTest.runtimeClasspath
                    useJUnitPlatform()
                    outputs.upToDateWhen { false }
                    finalizedBy jacocoAPIReport

                }

I don't see any of my application's classes in the jococo.exec file.我在 jococo.exec 文件中没有看到我的应用程序的任何类。 I think, bcz of that I am always getting the coverage report as 0%.我认为,因为我总是得到 0% 的覆盖率报告。

The server is running in my local on 8080 port.服务器在我本地的 8080 端口上运行。

I don't think that is going to work.我认为这不会奏效。 Depending on how your code is structured you need to instrument the code of the server.根据您的代码的结构,您需要检测服务器的代码。

I suggest trying to get a simple unit test of a Java method to work with Gradle.我建议尝试对 Java 方法进行简单的单元测试以使用 Gradle。 If that works, then use the same approach for the server-side code and it will work.如果可行,那么对服务器端代码使用相同的方法,它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM