我们使用gradle 3.3和jacoco工具verson 0.7.6.201602180812。我们有这样一个分级多项目:
我们在所有生成test.exec文件的子项目上使用单元测试,测试项目源和jacoco。我们在int-test项目中增加了额外的集成测试,在int-test项目中向test-exec添加了jacoco结果。我们在父项目上使用sonarqube插件(2.2.1)来收集SonarQube服务器v6.2的所有内容。
在他们自己的项目中测试源代码的测试中,一切都运行得很好:代码覆盖率是在jacoco报告和SonarQube上度量的。
只有prod-项目(单个过程)中的源的集成测试(int-test项目)覆盖范围,既没有在带有测试的项目中的覆盖报告中度量,也没有在带类的项目中度量。
也许需要将顶级项目的覆盖数据组合起来--有人知道怎么做吗?在最好的情况下,SonarQube仍然在单个模块级别上显示覆盖率。
编辑这里是一个小测试项目:运行https://github.com/MichaelZett/coveragetest
“'build sonarqube”导致:
发布于 2017-01-03 21:07:00
谈到SonarQube:您可以通过在所有模块中使用相同的jacoco.exec位置来获得聚合报告。确保在生成之前删除该文件,并将其追加到所有模块中。
只谈论格拉德尔:看看
发布于 2018-03-08 15:30:14
正如注释中所指出的,您必须首先使用合并Jacoco执行数据,然后告诉sonarqube使用该数据,而不是每个子模块生成的单个exec文件。
我在这里添加一个例子,因为在接受的答案中提供的链接有点误导。它们中的大多数为合并Jacoco报告提供了不同的解决方案,而不是合并执行数据,这正是您想要的。
下面是它的样子:
def allTestCoverageFile = "$buildDir/jacoco/allTestCoverage.exec"
sonarqube {
properties {
property "sonar.projectKey", "your.org:YourProject"
property "sonar.projectName", "YourProject"
property "sonar.jacoco.reportPaths", allTestCoverageFile
}
}
task jacocoMergeTest(type: JacocoMerge) {
destinationFile = file(allTestCoverageFile)
executionData = project.fileTree(dir: '.', include:'**/build/jacoco/test.exec')
}
task jacocoMerge(dependsOn: ['jacocoMergeTest']) {
// used to run the other merge tasks
}
subprojects {
sonarqube {
properties {
property "sonar.jacoco.reportPaths", allTestCoverageFile
}
}
}简而言之:
allTestCoverageFile)定义了一个全局覆盖文件输出。sonar.jacoco.reportPaths)。但是请注意,我们也必须在子项目关闭时这样做。这是非常重要的。别错过了。JacocoMerge ( Jacoco插件中的孵化类),它将来自所有项目(executionData)的所有测试覆盖率报告合并到我们的allTestCoverageFile中。如果您使用的是6.2之前的SonarQube版本,请使用sonar.jacoco.reportPath属性
发布于 2020-03-11 06:25:57
subprojects {
apply(plugin: 'org.jetbrains.kotlin.jvm')
repositories {
jcenter()
mavenCentral()
}
}
task codeCoverageReport(type: JacocoReport) {
// Gather execution data from all subprojects
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
// Add all relevant sourcesets from the subprojects
subprojects.each {
sourceSets it.sourceSets.main
}
reports {
xml.enabled true
html.enabled true
csv.enabled false
}
}
// always run the tests before generating the report
codeCoverageReport.dependsOn {
subprojects*.test
}
sonarqube {
properties {
property "sonar.projectKey", "your_project_key"
property "sonar.verbose", true
property "sonar.projectName", "Your project name"
property "sonar.coverage.jacoco.xmlReportPaths", "${rootDir}/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
}
}命令以覆盖范围运行测试:
./gradlew codeCoverageReport
./gradlew sonarqube -x test (test is excluded since already run and sonarqube by default executes test)值得注意的是,有两件事使它发挥作用:
https://stackoverflow.com/questions/41429841
复制相似问题