unbroken-dome / gradle-testsets-plugin

A plugin for the Gradle build system that allows specifying test sets (like integration or acceptance tests).
MIT License
230 stars 50 forks source link

Inconsistent JaCoCo report directory configured for additional JacocoReport tasks #100

Closed wujek-srujek closed 4 years ago

wujek-srujek commented 4 years ago

It turns out this plugin adds a JacocoReport task for each new test set. However, the report destination configuration is inconsistent, see (the module defines one additional 'integrationTest' source set).

$ ls build/reports/jacoco/
jacocoIntegrationTestReport  test

So, the default test task gets a (in my case HTML, but I checked all reports and it is the same) report folder named after the source set/Test task name, but jacocoIntegrationTestReport is named after the additional JaCoCo task name. I guess the 'destination' property of each report should be set to use the additional Test task name, in this case 'integrationTest'. I think the code in the JaCoCo plugin is this: https://github.com/gradle/gradle/blob/master/subprojects/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoPlugin.java#L190

tkrullmann commented 4 years ago

The test-sets plugin doesn't do anything to set the reports output directory; turns out that the task name is the default.

For the jacocoTestReport task that is auto-generated by the jacoco plugin, the JacocoPlugin configures this "special" task differently. Interestingly, the corresponding Gradle code contains a TODO that mentions this might be changed to the general convention of using the task name soon.

// TODO: Change the default location for these reports to follow the convention defined in #configureReportOutputDirectory

So for now I would refrain in this plugin from mimicking behavior in another plugin that is due to be changed soon. If anyone wants to do this manually, the following code replicates what the JacocoPlugin does to the default report task:

 testSets.all { testSet ->
    tasks[testSet.jacocoReportTaskName].reports.all { ConfigurableReport report ->
        if (report.outputType == Report.OutputType.DIRECTORY) {
            report.destination = file("${jacoco.reportsDir}/${testSet.name}/${report.name}")
        } else {
            report.destination = file("${jacoco.reportsDir}/${testSet.name}/${testSet.jacocoReportTaskName}.${report.name}")
        }
    }
}