# The Test Report Aggregation Plugin

version 7.6.4

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 → distribution sample

2. Using a standalone project to specify subprojects → standalone sample

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.type        = unit-test      (2)
        - org.gradle.verificationtype      = test-results   (3)

1 | Category attribute; value is fixed.
2 | TestSuiteType attribute; value is derived from JvmTestSuite#getTestType().
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 a container to parameterize the TestSuiteType value.

### Manual report creation

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

Example 1. Create a reporting container
build.gradle

    reporting {
        reports {
            testAggregateTestReport(AggregateTestReport) { (1)
                testType = TestSuiteType.UNIT_TEST
            }
        }
    }

build.gradle.kts

    reporting {
        reports {
            val testAggregateTestReport by creating(AggregateTestReport::class) { (1)
                testType.set(TestSuiteType.UNIT_TEST)
            }
        }
    }

1 | Creates a report named `testAggregateTestReport` of type `AggregateTestReport`. For convenience, sets `TestType` using a constant value from the TestSuiteType class. Any String value is acceptable.

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.
`testReportNameResults` | 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.

Note the `testReportNameResults` configuration may display resolution errors for external dependencies, as these do not expose test result data. This is expected behavior and does not affect the outcome of the build or test report aggregation process.