Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

gradle - 如何使用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)首先,我尝试通过gradle任务在jacocoagent.jar的帮助下生成jacoco执行数据:)

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%。)

  ask by Hima Bindu translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. (如果可行,则对服务器端代码使用相同的方法,它将起作用。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...