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

1

7

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

Tarboosh answered 7/3, 2022 at 9:19 Comment(2)
Were you able to figure out a solution to this?Hinckley
If you copy all the exec files to a single location using Gradle, and give Jacoco that, does it work?Chuck
J
-1
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
                        }
                    }
                }
            }
        }
    }
}
Juju answered 9/2, 2023 at 2:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.