# The Test Report Aggregation Plugin

version 9.5.1

The Test Report Aggregation plugin (plugin id: `test-report-aggregation`) provides tasks and configurations used to aggregate the results of multiple Test task invocations (potentially spanning multiple Gradle projects) into a single HTML report.

## Usage

To use the Test Report Aggregation plugin, include the following in your build script:

    plugins {
        id 'test-report-aggregation'
    }

    plugins {
        id("test-report-aggregation")
    }

Note that this plugin takes no action unless applied in concert with the JVM Test Suite Plugin. The Java Plugin automatically applies the JVM Test Suite Plugin.

There are now two ways to collect test results across multiple subprojects:

1. From the distribution’s project, such as an application or WAR subproject

2. Using a standalone project to specify subprojects

Example 2 could also be used to aggregate results via the root project.

| The Test Report Aggregation plugin does not currently work with the `com.android.application` plugin.

## Tasks

When the project also applies the `jvm-test-suite` plugin, the following tasks are added for each test suite:

`testSuiteAggregateTestReport` — TestReport

  Depends on: Artifacts of variants matching the below attributes

  Collects variants of direct and transitive project dependencies via the `testReportAggregation` configuration. The following Attributes will be matched:

        - org.gradle.category         = verification   (1)
        - org.gradle.testsuite.name   = test           (2)
        - org.gradle.verificationtype = test-results   (3)

1 | Category attribute; value is fixed.
2 | TestSuiteName attribute; value is derived from TestSuite#getName().
3 | VerificationType attribute; value is fixed.

More information about the variants produced by test execution are available in the Outgoing Variants section of the JVM Test Suite Plugin documentation.

## Reports

| By default, Gradle stops executing tasks when any task fails — including test failures. To ensure that your builds always generate aggregation reports, specify the `--continue` option in your Gradle command. For more information, see continuing the build when a failure occurs.

### Automatic report creation

When the project also applies the `jvm-test-suite` plugin, the following reporting objects are added for each test suite:

`testSuiteAggregateTestReport` — AggregateTestReport

  Creates an aggregate Jacoco report aggregating all test suites with a given name across all project dependencies.

### Manual report creation

When the project does not apply the `jvm-test-suite` plugin, you must manually register one or more reports:

build.gradle.kts

    reporting {
        reports {
            val testAggregateTestReport by creating(AggregateTestReport::class) { (1)
                testSuiteName = "test"
            }
        }
    }

build.gradle

    reporting {
        reports {
            testAggregateTestReport(AggregateTestReport) { (1)
                testSuiteName = "test"
            }
        }
    }

1 | Creates a report named `testAggregateTestReport` of type `AggregateTestReport`, aggregating all test suites from all project dependencies with a given TestSuite#getName().

Report creation automatically creates backing tasks to aggregate by the given test suite type value.

## Dependency management

The Test Report Aggregation plugin adds the following dependency configurations:

Table 1. Test Report Aggregation plugin - dependency configurations
Name | Meaning
--- | ---
`testReportAggregation` | The configuration used to declare all project dependencies having test result data to be aggregated.
`aggregateTestReportResults` | Consumes the project dependencies from the `testReportAggregation` configuration using variant-aware matching to find the appropriate test suite type.

It is not necessary to explicitly add dependencies to the `testReportAggregation` configuration if the project also applies the `jvm-test-suite` plugin.