Merge coverage unit and integration test result generated with jacoco-report-aggregation plugin on gradle 7.4

1.7k Views Asked by At

I am migrating my project to Gradle 7.4 and i would like to use the new plugin jacoco-report-aggregation to generate unit and integration test coverage report perfectly merged to be sent to sonarqube.

i m using jvm testing suite on each subproject.

Before that i used to merge manually exec file in each sub project and it worked good

So I ve created two tasks: testCodeCoverageReport and integrationTestCodeCoverageReport targeting TestSuiteType.UNIT_TEST and TestSuiteType.INEGRATION_TEST testType and i sent the reports to sonarqube.

my configuration:

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"

}

But the computed coverage is not good . Ideally reports would be merged before sending to sonarqube.

Is it possible to do something which seems like this?

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"

}

Thank for answer

1

There are 1 best solutions below

0
On
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
                        }
                    }
                }
            }
        }
    }
}