我正在将我的项目迁移到Gradle 7.4,我希望使用新插件jacoco-report-aggregation生成单元和集成测试覆盖率报告,并将其完美地合并发送到sonarqube。
我在每个子项目上使用jvm测试套件。
在此之前,我习惯于手动合并每个子项目中的可执行文件,效果很好
因此,我创建了两个任务:针对测试套件类型的测试代码覆盖率报告和集成测试代码覆盖率报告。UNIT_TEST和测试套件类型。INEGRATION_TEST测试类型和i将报告发送到sonarqube。
我的配置:
plugins {
id "org.sonarqube" version "3.3"
id "org.owasp.dependencycheck" version "6.4.1.1"
id 'org.springframework.boot' version "$springBootVersion"
// Aggregating code coverage with JaCoCo
id 'jacoco-report-aggregation'
}
dependencies {
jacocoAggregation project(':subproject1')
jacocoAggregation project(':subproject2')
}
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
testType = TestSuiteType.UNIT_TEST
}
integrationTestCodeCoverageReport(JacocoCoverageReport) {
testType = TestSuiteType.INTEGRATION_TEST
}
}
}
project.tasks["sonarqube"].dependsOn tasks.named('testCodeCoverageReport', JacocoReport)
project.tasks["sonarqube"].dependsOn tasks.named('integrationTestCodeCoverageReport', JacocoReport)
sonarqube.properties {
property "sonar.coverage.jacoco.xmlReportPaths", "$buildDir/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml,$buildDir/reports/jacoco/integrationTestCodeCoverageReport/integrationTestCodeCoverageReport.xml"
}
但是计算出来的覆盖率并不理想,理想情况下报告应该在发送到sonarqube之前进行合并。
有可能做一些看起来像这样的事情吗?
reporting {
reports {
perfectMergeUnitAndIntegrationCodeCoverageReport(JacocoCoverageReport) {
testTypes = [TestSuiteType.UNIT_TEST, TestSuiteType.INTEGRATION_TEST]
}
}
}
project.tasks["sonarqube"].dependsOn tasks.named('perfectMergeUnitAndIntegrationCodeCoverageReport', JacocoReport)
sonarqube.properties {
property "sonar.coverage.jacoco.xmlReportPaths", "$buildDir/reports/jacoco/perfectMergeUnitAndIntegrationCodeCoverageReport/perfectMergeUnitAndIntegrationCodeCoverageReport.xml"
}
谢谢你的回答
1条答案
按热度按时间dxpyg8gm1#