在Gradle 7.4上使用jacoco-report-aggregation插件生成合并覆盖单元和集成测试结果

jjhzyzn0  于 2023-02-13  发布在  其他
关注(0)|答案(1)|浏览(394)

我正在将我的项目迁移到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"

}

谢谢你的回答

dxpyg8gm

dxpyg8gm1#

reporting {
    reports {
        testCodeCoverageReport(JacocoCoverageReport) {
            testType = TestSuiteType.UNIT_TEST
            jacocoTestCoverageVerification {
                afterEvaluate {       
getClassDirectories().setFrom(filesToExcludeFromCoverageReport)
                }
                dependsOn(test,integrationTest)
                executionData.from = files("$buildDir/jacoco/test.exec", "$buildDir/jacoco/intergrationTest.exec")
                violationRules {
                    rule {
                        limit {
                            minimum = 0.80
                        }
                    }
                }
            }
        }
    }
}

相关问题