如何使用Gradle获取有关空手道测试功能文件的Jacoco报告 [英] How to get Jacoco reports for the Karate test feature files using gradle
问题描述
如何使用Gradle获取有关空手道测试功能文件的Jacoco报告.
How to get Jacoco reports for the Karate test feature files using Gradle.
我的项目是Gradle项目,我正在尝试将jacoco报告功能集成到我的项目中以进行空手道测试.服务器正在本地8080端口上运行.
My project is a Gradle project and I am trying to integrate jacoco report feature in my project for the karate tests. The server is running in my local on 8080 port.
我正在按照以下方式生成jacoco报告,请让我知道我的方法是正确的,并且还为我提供了获取gradle项目的jacoco报告的解决方案.
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.
1)首先,我尝试通过gradle任务在jacocoagent.jar的帮助下生成jacoco执行数据:
1) First I am trying to generate jacoco execution data with the help of jacocoagent.jar as follows with a Gradle task:
java -javaagent:/pathtojacocojar/jacocoagent.jar=destfile=/pathtojocofile/jacoco.exec -jar my-app.jar
2)接下来,我正在运行Gradle任务来生成报告
2) Next, I am running a Gradle task to generate the report
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
}
在jococo.exec文件中没有看到我的应用程序的任何类.我认为,我始终将覆盖率报告设为0%.
I don't see any of my application's classes in the jococo.exec file. I think, bcz of that I am always getting the coverage report as 0%.
推荐答案
服务器在我的本地8080端口上运行.
The server is running in my local on 8080 port.
我认为这不会起作用.根据代码的结构,您需要检测服务器的代码.
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.
我建议尝试对Java方法进行简单的单元测试以与Gradle一起使用.如果可行,则对服务器端代码使用相同的方法,它将起作用.
I suggest trying to get a simple unit test of a Java method to work with Gradle. If that works, then use the same approach for the server-side code and it will work.
这篇关于如何使用Gradle获取有关空手道测试功能文件的Jacoco报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!