[英]sonarqube+jacoco+junit code coverage showing 0% in sonarqube dashboard
I am using sonarqube + jacoco for codecoverage, i have junit test case for my java code in below dir structure.我正在使用 sonarqube + jacoco 进行代码覆盖,我的 java 代码在下面的 dir 结构中有 junit 测试用例。
src/main/java/code/abc.java
src/main/test/code/Testabc.java
I want a code coverage on sonarqube dashboard and i am using gradle for the same.我想要 sonarqube 仪表板的代码覆盖率,并且我正在使用 gradle 进行相同的操作。
apply plugin: "java"
apply plugin: "org.sonarqube"
apply plugin: "jacoco"
jacoco {
toolVersion = "0.7.9"
reportsDir = file("${project.buildDir}/jacoco/customJacocoReportDir")
}
sonarqube {
properties {
property "sonar.sources", "."
property "sonar.projectName", "javacode"
property "sonar.projectKey", "javacode"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.java.binaries", "/data/tmp/env/"
property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7"
}
}
I am running gradle sonarqube
我正在运行
gradle sonarqube
I dont know where i am doing wrong?我不知道我在哪里做错了? if any one can help to get the coverage of test case written from java code.
如果有人可以帮助获得从 java 代码编写的测试用例的覆盖率。
It seems to me, that Jacoco test reports are generated in one directory, but SoanrQube is configured to look into another one.在我看来,Jacoco 测试报告是在一个目录中生成的,但 SoanrQube 被配置为查看另一个目录。 Here is the directory you save reports:
这是您保存报告的目录:
reportsDir = file("${project.buildDir}/jacoco/customJacocoReportDir")
and here is Sonar configuration to look up Jacoco results:这是用于查找 Jacoco 结果的声纳配置:
property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
There is customJacocoReportDir
directory missed customJacocoReportDir
目录
Here's the minimal config that is working with这是正在使用的最小配置
Gradle snippet: Gradle 片段:
apply plugin: "org.sonarqube"
apply plugin: "jacoco"
// jacoco task config not needed since I'm using the defaults (latest version, default dir)
// jacoco {
// toolVersion = "0.7.9"
// reportsDir = file("${project.buildDir}/jacoco/customJacocoReportDir")
// }
sonarqube {
properties {
property "sonar.sources", "."
property "sonar.projectName", "javacode"
property "sonar.projectKey", "javacode"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.java.binaries", "/data/tmp/env/"
// no need to define sonar.jacoco.reportPaths or sonar.coverage.jacoco.xmlReportPaths as sonarqube
// finds the xml report in the default location (build/reports/jacoco/test/jacocoTestReport.xml)
// property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
}
}
jacocoTestReport {
reports {
xml.enabled true // to be sure xml report is created (sonarqube knows jacoco's default report location)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.