Automatically create test results elements for each test suite
Previously, we created a binary test results elements for each test target.
When performing aggregation, this only worked if the target test suite had a single target. Otherwise, we'd run into ambiguity.
To resolve this for multi-target test suites, we only create a single variant for each sutie and add all test results variants for all targets to the suite's variant.
This means when aggregating against a project, we will aggregate the results of all targets.
Eventually we will want to go back to a test results variant for each target, but until we have the targets able to declare their identity via attributes, we will have a single variant per suite.
We remove the concept of a test suite type, as this was a very simple mapping over the suite name, and only differed for the case of the default test suite, which has a test type of UNIT_TEST instead of its suite name.
We will eventually want to not use the suite name as an attribute either, but rather use the suite name as part of a capability.
The reports will eventually want to use attributes to distinguish which targets to aggregate instead of aggregating all targets from each suite.
We also make similar changes to Jacoco.
diff --git a/platforms/documentation/docs/src/docs/dsl/org.gradle.api.plugins.jvm.JvmTestSuite.xml b/platforms/documentation/docs/src/docs/dsl/org.gradle.api.plugins.jvm.JvmTestSuite.xml
index 1ecc292..3841b34 100644
--- a/platforms/documentation/docs/src/docs/dsl/org.gradle.api.plugins.jvm.JvmTestSuite.xml
+++ b/platforms/documentation/docs/src/docs/dsl/org.gradle.api.plugins.jvm.JvmTestSuite.xml
@@ -32,9 +32,6 @@
<tr>
<td>targets</td>
</tr>
- <tr>
- <td>testType</td>
- </tr>
</table>
</section>
<section>
diff --git a/platforms/documentation/docs/src/docs/dsl/org.gradle.api.tasks.testing.AggregateTestReport.xml b/platforms/documentation/docs/src/docs/dsl/org.gradle.api.tasks.testing.AggregateTestReport.xml
index 60e7e8c..71eb314 100644
--- a/platforms/documentation/docs/src/docs/dsl/org.gradle.api.tasks.testing.AggregateTestReport.xml
+++ b/platforms/documentation/docs/src/docs/dsl/org.gradle.api.tasks.testing.AggregateTestReport.xml
@@ -27,7 +27,7 @@
<td>reportTask</td>
</tr>
<tr>
- <td>testType</td>
+ <td>testSuiteName</td>
</tr>
</table>
</section>
diff --git a/platforms/documentation/docs/src/docs/dsl/org.gradle.testing.base.TestSuiteTarget.xml b/platforms/documentation/docs/src/docs/dsl/org.gradle.testing.base.TestSuiteTarget.xml
index 6628b3d..2a0207e 100644
--- a/platforms/documentation/docs/src/docs/dsl/org.gradle.testing.base.TestSuiteTarget.xml
+++ b/platforms/documentation/docs/src/docs/dsl/org.gradle.testing.base.TestSuiteTarget.xml
@@ -23,6 +23,9 @@
<td>Name</td>
</tr>
</thead>
+ <tr>
+ <td>binaryTestResultsDirectory</td>
+ </tr>
</table>
</section>
<section>
diff --git a/platforms/documentation/docs/src/docs/dsl/org.gradle.testing.jacoco.plugins.JacocoCoverageReport.xml b/platforms/documentation/docs/src/docs/dsl/org.gradle.testing.jacoco.plugins.JacocoCoverageReport.xml
index 60e7e8c..71eb314 100644
--- a/platforms/documentation/docs/src/docs/dsl/org.gradle.testing.jacoco.plugins.JacocoCoverageReport.xml
+++ b/platforms/documentation/docs/src/docs/dsl/org.gradle.testing.jacoco.plugins.JacocoCoverageReport.xml
@@ -27,7 +27,7 @@
<td>reportTask</td>
</tr>
<tr>
- <td>testType</td>
+ <td>testSuiteName</td>
</tr>
</table>
</section>
diff --git a/platforms/documentation/docs/src/docs/userguide/core-plugins/jacoco_plugin.adoc b/platforms/documentation/docs/src/docs/userguide/core-plugins/jacoco_plugin.adoc
index 79744b1..ea0bfc7 100644
--- a/platforms/documentation/docs/src/docs/userguide/core-plugins/jacoco_plugin.adoc
+++ b/platforms/documentation/docs/src/docs/userguide/core-plugins/jacoco_plugin.adoc
@@ -189,20 +189,16 @@
--------------------------------------------------
Variant coverageDataElementsForTest (i)
--------------------------------------------------
-Description = Binary data file containing results of Jacoco test coverage reporting for the test Test Suite's test target.
+Binary results containing Jacoco test coverage for all targets in the 'test' Test Suite.
Capabilities
- org.gradle.sample:application:1.0.2 (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test // <1>
- - org.gradle.testsuite.target.name = test // <2>
- - org.gradle.testsuite.type = unit-test // <3>
- - org.gradle.verificationtype = jacoco-coverage
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test // <1>
+ - org.gradle.verificationtype = jacoco-coverage
Artifacts
- build/jacoco/test.exec (artifactType = binary)
----
-<1> TestSuiteName attribute; value is derived from link:{javadocPath}/org/gradle/api/plugins/jvm/JvmTestSuite.html#getName--[JvmTestSuite#getName()].
-<2> TestSuiteTargetName attribute; value is derived from link:{javadocPath}/org/gradle/api/plugins/jvm/JvmTestSuiteTarget.html#getName--[JvmTestSuiteTarget#getName()].
-<3> TestSuiteType attribute; value is derived from link:{javadocPath}/org/gradle/api/plugins/jvm/JvmTestSuite.html#getTestType--[JvmTestSuite#getTestType()].
+<1> TestSuiteName attribute; value is derived from link:{javadocPath}/org/gradle/testing/base/TestSuite.html#getName--[TestSuite#getName()].
diff --git a/platforms/documentation/docs/src/docs/userguide/dep-man/understanding-dependency-resolution/variant_attributes.adoc b/platforms/documentation/docs/src/docs/userguide/dep-man/understanding-dependency-resolution/variant_attributes.adoc
index 808ea4e..13a6a60 100644
--- a/platforms/documentation/docs/src/docs/userguide/dep-man/understanding-dependency-resolution/variant_attributes.adoc
+++ b/platforms/documentation/docs/src/docs/userguide/dep-man/understanding-dependency-resolution/variant_attributes.adoc
@@ -137,20 +137,10 @@
| Common values are `standard-jvm` and `android`. Other values are allowed.
| The attribute is used to prefer one variant over another if multiple are available, but in general all values are compatible. The default is `standard-jvm`.
-| link:{javadocPath}/org/gradle/api/attributes/TestSuiteType.html#TEST_SUITE_NAME_ATTRIBUTE[`org.gradle.testsuite.name`]
+| link:{javadocPath}/org/gradle/api/attributes/TestSuiteName.html#TEST_SUITE_NAME_ATTRIBUTE[`org.gradle.testsuite.name`]
| Indicates the name of the link:{javadocPath}/org/gradle/testing/base/TestSuite.html[TestSuite] that produced this output.
| Value is the name of the Suite.
| No default, no compatibility
-
-| link:{javadocPath}/org/gradle/api/attributes/TestSuiteTargetName.html#TEST_SUITE_TARGET_NAME_ATTRIBUTE[`org.gradle.testsuite.target.name`]
-| Indicates the name of the link:{javadocPath}/org/gradle/testing/base/TestSuiteTarget.html[TestSuiteTarget] that produced this output.
-| Value is the name of the Target.
-| No default, no compatibility
-
-| link:{javadocPath}/org/gradle/api/attributes/TestSuiteType.html#TEST_SUITE_TYPE_ATTRIBUTE[`org.gradle.testsuite.type`]
-| Indicates the type of test suite (unit test, integration test, performance test, etc.)
-| `TestSuiteType` values built from constants defined in link:{javadocPath}/org/gradle/api/attributes/TestSuiteType.html[TestSuiteType] or other custom values for user-defined test suite types.
-| No default, no compatibility
|===
The JVM ecosystem also contains a number of compatibility and disambiguation rules over the different attributes.
diff --git a/platforms/documentation/docs/src/docs/userguide/jvm/jacoco_report_aggregation_plugin.adoc b/platforms/documentation/docs/src/docs/userguide/jvm/jacoco_report_aggregation_plugin.adoc
index 517ea4c..4d23766 100644
--- a/platforms/documentation/docs/src/docs/userguide/jvm/jacoco_report_aggregation_plugin.adoc
+++ b/platforms/documentation/docs/src/docs/userguide/jvm/jacoco_report_aggregation_plugin.adoc
@@ -58,12 +58,12 @@
[source]
----
- - org.gradle.category = verification // <1>
- - org.gradle.testsuite.type = unit-test // <2>
- - org.gradle.verificationtype = jacoco-results // <3>
+ - org.gradle.category = verification // <1>
+ - org.gradle.testsuite.name = test // <2>
+ - org.gradle.verificationtype = jacoco-results // <3>
----
<1> Category attribute; value is fixed.
-<2> TestSuiteType attribute; value is derived from link:{javadocPath}/org/gradle/api/plugins/jvm/JvmTestSuite.html#getTestType--[JvmTestSuite#getTestType()].
+<2> TestSuiteName attribute; value is derived from link:{javadocPath}/org/gradle/testing/base/TestSuite.html#getName--[TestSuite#getName()].
<3> VerificationType attribute; value is fixed.
More information about the variants produced by test execution with JaCoCo are available in the <<jacoco_plugin#sec:outgoing_variants,Outgoing Variants>> section of the JaCoCo Plugin documentation.
@@ -82,7 +82,7 @@
When the project also applies the `jvm-test-suite` plugin, the following reporting objects are added for each test suite:
`__testSuite__CodeCoverageReport` — link:{javadocPath}/org/gradle/testing/jacoco/plugins/JacocoCoverageReport.html[JacocoCoverageReport]::
-Creates a container to parameterize the link:{javadocPath}/org/gradle/api/attributes/TestSuiteType.html[TestSuiteType] value.
+Creates an aggregate Jacoco report aggregating all test suites with a given link:{javadocPath}/org/gradle/api/attributes/TestSuiteName.html[name] across all project dependencies.
=== Manual report creation
@@ -93,7 +93,7 @@
include::sample[dir="samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/kotlin/code-coverage-report",files="build.gradle.kts[tags=create_report]"]
include::sample[dir="samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/groovy/code-coverage-report",files="build.gradle[tags=create_report]"]
====
-<.> Creates a report named `testCodeCoverageReport` of type `JacocoCoverageReport`. For convenience, sets `TestType` using a constant value from the link:{javadocPath}/org/gradle/api/attributes/TestSuiteType.html[TestSuiteType] class. Any String value is acceptable.
+<.> Creates a report named `testCodeCoverageReport` of type `JacocoCoverageReport`, aggregating all test suites from all project dependencies with a given link:{javadocPath}/org/gradle/testing/base/TestSuite.html#getName--[TestSuite#getName()].
Report creation automatically creates backing tasks to aggregate coverage results for the given test suite type value.
diff --git a/platforms/documentation/docs/src/docs/userguide/jvm/jvm_test_suite_plugin.adoc b/platforms/documentation/docs/src/docs/userguide/jvm/jvm_test_suite_plugin.adoc
index 1369ffa4..6dae36a 100644
--- a/platforms/documentation/docs/src/docs/userguide/jvm/jvm_test_suite_plugin.adoc
+++ b/platforms/documentation/docs/src/docs/userguide/jvm/jvm_test_suite_plugin.adoc
@@ -82,16 +82,6 @@
The `Test` task associated with the target inherits its name from the suite. Other properties of the `Test` task are configurable.
-==== Test Suite Type ====
-Each test suite must be assigned a type.
-Types can be used to group related test suites across multiple Gradle projects within a build.
-
-The type of a test suite can be configured using the suites's link:{groovyDslPath}/org.gradle.api.plugins.jvm.JvmTestSuite.html#getTestType[test type property].
-The type *must be unique* across all test suites in the same Gradle project.
-By convention, the type is set to the name of the test suite, converted to dash-case - with the exception of the built-in test suite, which uses the value link:{javadocPath}/org/gradle/api/attributes/TestSuiteType.html#UNIT_TEST--['unit-test'].
-
-Common values are available as constants in link:{javadocPath}/org/gradle/api/attributes/TestSuiteType.html[TestSuiteType].
-
[[sec:jvm_test_suite_examples]]
[discrete]
== Configuration Examples
@@ -165,15 +155,6 @@
<3> Configure the `java` SourceDirectorySet of the test suite.
<4> Overwrite the `srcDirs` property, replacing the conventional `src/integrationTest/java` location with `src/it/java`.
-== Configure the type of a test suite
-
-====
-include::sample[dir="snippets/testing/test-suite-configure-type/kotlin",files="build.gradle.kts[tags=configure-type]"]
-include::sample[dir="snippets/testing/test-suite-configure-type/groovy",files="build.gradle[tags=configure-type]"]
-====
-
-<1> This suite would use a type value of 'secondary-test' by default. This explicitly sets the type to 'integration-test'.
-
== Configure the `Test` task for a test suite
====
include::sample[dir="snippets/testing/test-suite-configure-source-dir/kotlin",files="build.gradle.kts[tags=configure-test-task]"]
@@ -269,15 +250,11 @@
Capabilities
- org.gradle.sample:list:1.0.2 (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test // <1>
- - org.gradle.testsuite.target.name = test // <2>
- - org.gradle.testsuite.type = unit-test // <3>
- - org.gradle.verificationtype = test-results
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test // <1>
+ - org.gradle.verificationtype = test-results
Artifacts
- build/test-results/test/binary (artifactType = directory)
----
-<1> TestSuiteName attribute; value is derived from link:{javadocPath}/org/gradle/api/plugins/jvm/JvmTestSuite.html#getName--[JvmTestSuite#getName()].
-<2> TestSuiteTargetName attribute; value is derived from link:{javadocPath}/org/gradle/api/plugins/jvm/JvmTestSuiteTarget.html#getName--[JvmTestSuiteTarget#getName()].
-<3> TestSuiteType attribute; value is derived from link:{javadocPath}/org/gradle/api/plugins/jvm/JvmTestSuite.html#getTestType--[JvmTestSuite#getTestType()].
+<1> TestSuiteName attribute; value is derived from link:{javadocPath}/org/gradle/testing/base/TestSuite.html#getName--[TestSuite#getName()].
diff --git a/platforms/documentation/docs/src/docs/userguide/jvm/test_report_aggregation_plugin.adoc b/platforms/documentation/docs/src/docs/userguide/jvm/test_report_aggregation_plugin.adoc
index 47fa16e..885fe3b 100644
--- a/platforms/documentation/docs/src/docs/userguide/jvm/test_report_aggregation_plugin.adoc
+++ b/platforms/documentation/docs/src/docs/userguide/jvm/test_report_aggregation_plugin.adoc
@@ -58,12 +58,12 @@
[source]
----
- - org.gradle.category = verification // <1>
- - org.gradle.testsuite.type = unit-test // <2>
- - org.gradle.verificationtype = test-results // <3>
+ - org.gradle.category = verification // <1>
+ - org.gradle.testsuite.name = test // <2>
+ - org.gradle.verificationtype = test-results // <3>
----
<1> Category attribute; value is fixed.
-<2> TestSuiteType attribute; value is derived from link:{javadocPath}/org/gradle/api/plugins/jvm/JvmTestSuite.html#getTestType--[JvmTestSuite#getTestType()].
+<2> TestSuiteName attribute; value is derived from link:{javadocPath}/org/gradle/testing/base/TestSuite.html#getName--[TestSuite#getName()].
<3> VerificationType attribute; value is fixed.
More information about the variants produced by test execution are available in the <<jvm_test_suite_plugin#sec:outgoing_variants,Outgoing Variants>> section of the JVM Test Suite Plugin documentation.
@@ -82,7 +82,7 @@
When the project also applies the `jvm-test-suite` plugin, the following reporting objects are added for each test suite:
`__testSuite__AggregateTestReport` — link:{javadocPath}/org/gradle/api/tasks/testing/AggregateTestReport.html[AggregateTestReport]::
-Creates a container to parameterize the link:{javadocPath}/org/gradle/api/attributes/TestSuiteType.html[TestSuiteType] value.
+Creates an aggregate Jacoco report aggregating all test suites with a given link:{javadocPath}/org/gradle/api/attributes/TestSuiteName.html[name] across all project dependencies.
=== Manual report creation
@@ -93,7 +93,7 @@
include::sample[dir="samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/kotlin/test-results",files="build.gradle.kts[tags=create_report]"]
include::sample[dir="samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/groovy/test-results",files="build.gradle[tags=create_report]"]
====
-<.> Creates a report named `testAggregateTestReport` of type `AggregateTestReport`. For convenience, sets `TestType` using a constant value from the link:{javadocPath}/org/gradle/api/attributes/TestSuiteType.html[TestSuiteType] class. Any String value is acceptable.
+<.> Creates a report named `testAggregateTestReport` of type `AggregateTestReport`, aggregating all test suites from all project dependencies with a given link:{javadocPath}/org/gradle/testing/base/TestSuite.html#getName--[TestSuite#getName()].
Report creation automatically creates backing tasks to aggregate by the given test suite type value.
diff --git a/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/groovy/code-coverage-report/build.gradle b/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/groovy/code-coverage-report/build.gradle
index be6d2e8..73b032d 100644
--- a/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/groovy/code-coverage-report/build.gradle
+++ b/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/groovy/code-coverage-report/build.gradle
@@ -15,7 +15,7 @@
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) { // <.>
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
diff --git a/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/kotlin/code-coverage-report/build.gradle.kts b/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/kotlin/code-coverage-report/build.gradle.kts
index 54ede84..aa75469 100644
--- a/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/kotlin/code-coverage-report/build.gradle.kts
+++ b/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-code-coverage-standalone/kotlin/code-coverage-report/build.gradle.kts
@@ -15,7 +15,7 @@
reporting {
reports {
val testCodeCoverageReport by creating(JacocoCoverageReport::class) { // <.>
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
diff --git a/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/groovy/test-results/build.gradle b/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/groovy/test-results/build.gradle
index 6dc6de0..9263b48 100644
--- a/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/groovy/test-results/build.gradle
+++ b/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/groovy/test-results/build.gradle
@@ -11,7 +11,7 @@
reporting {
reports {
testAggregateTestReport(AggregateTestReport) { // <.>
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
diff --git a/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/kotlin/test-results/build.gradle.kts b/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/kotlin/test-results/build.gradle.kts
index 54a4fd8..8adcb15 100644
--- a/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/kotlin/test-results/build.gradle.kts
+++ b/platforms/documentation/docs/src/samples/incubating/java/jvm-multi-project-with-test-aggregation-standalone/kotlin/test-results/build.gradle.kts
@@ -11,7 +11,7 @@
reporting {
reports {
val testAggregateTestReport by creating(AggregateTestReport::class) { // <.>
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
diff --git a/platforms/documentation/docs/src/snippets/testing/test-suite-configure-type/groovy/build.gradle b/platforms/documentation/docs/src/snippets/testing/test-suite-configure-type/groovy/build.gradle
deleted file mode 100644
index 042c231..0000000
--- a/platforms/documentation/docs/src/snippets/testing/test-suite-configure-type/groovy/build.gradle
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-plugins {
- id 'java'
-}
-
-version = '1.0.2'
-group = 'org.gradle.sample'
-
-repositories {
- mavenCentral()
-}
-
-// tag::configure-type[]
-testing {
- suites {
- secondaryTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST // <1>
- }
- }
-}
-// end::configure-type[]
diff --git a/platforms/documentation/docs/src/snippets/testing/test-suite-configure-type/kotlin/build.gradle.kts b/platforms/documentation/docs/src/snippets/testing/test-suite-configure-type/kotlin/build.gradle.kts
deleted file mode 100644
index a642c2b..0000000
--- a/platforms/documentation/docs/src/snippets/testing/test-suite-configure-type/kotlin/build.gradle.kts
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-plugins {
- java
-}
-
-version = "1.0.2"
-group = "org.gradle.sample"
-
-repositories {
- mavenCentral()
-}
-
-// tag::configure-type[]
-testing {
- suites {
- val secondaryTest by registering(JvmTestSuite::class) {
- testType = TestSuiteType.INTEGRATION_TEST // <1>
- }
- }
-}
-// end::configure-type[]
diff --git a/platforms/documentation/docs/src/snippets/testing/test-suite-configure-type/tests/testsuite.sample.conf b/platforms/documentation/docs/src/snippets/testing/test-suite-configure-type/tests/testsuite.sample.conf
deleted file mode 100644
index 51a1b53..0000000
--- a/platforms/documentation/docs/src/snippets/testing/test-suite-configure-type/tests/testsuite.sample.conf
+++ /dev/null
@@ -1,2 +0,0 @@
-executable: gradle
-args: test
diff --git a/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoAggregationIntegrationTest.groovy b/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoAggregationIntegrationTest.groovy
index f6a797e..e98f135 100644
--- a/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoAggregationIntegrationTest.groovy
+++ b/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoAggregationIntegrationTest.groovy
@@ -277,7 +277,6 @@
testing {
suites {
integTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
useJUnit()
dependencies {
implementation project()
@@ -292,7 +291,6 @@
testing {
suites {
integTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
useJUnit()
dependencies {
implementation project(':transitive') // necessary to access Divisor when compiling test
@@ -385,7 +383,7 @@
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
@@ -421,7 +419,7 @@
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
@@ -468,7 +466,7 @@
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
@@ -515,7 +513,7 @@
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
@@ -706,9 +704,7 @@
reporting {
reports {
- create("testCodeCoverageReport", JacocoCoverageReport) {
- testType.set(TestSuiteType.UNIT_TEST)
- }
+ create("testCodeCoverageReport", JacocoCoverageReport)
}
}
"""
diff --git a/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoConfigurationCacheIntegrationTest.groovy b/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoConfigurationCacheIntegrationTest.groovy
index c2915b0..6bfa82d 100644
--- a/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoConfigurationCacheIntegrationTest.groovy
+++ b/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoConfigurationCacheIntegrationTest.groovy
@@ -45,7 +45,7 @@
reporting {
reports {
val testCodeCoverageReport by creating(JacocoCoverageReport::class) {
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
diff --git a/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoKotlinJvmPluginAggregationTest.groovy b/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoKotlinJvmPluginAggregationTest.groovy
index 0bce978..d9b0096 100644
--- a/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoKotlinJvmPluginAggregationTest.groovy
+++ b/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoKotlinJvmPluginAggregationTest.groovy
@@ -51,7 +51,7 @@
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
diff --git a/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoPluginIntegrationTest.groovy b/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoPluginIntegrationTest.groovy
index e7ebeae..4a9af48 100644
--- a/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoPluginIntegrationTest.groovy
+++ b/platforms/jvm/jacoco/src/integTest/groovy/org/gradle/testing/jacoco/plugins/JacocoPluginIntegrationTest.groovy
@@ -155,16 +155,14 @@
--------------------------------------------------
Variant coverageDataElementsForTest (i)
--------------------------------------------------
-Binary data file containing results of Jacoco test coverage reporting for the test Test Suite's test target.
+Binary results containing Jacoco test coverage for all targets in the 'test' Test Suite.
Capabilities
- :Test:unspecified (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test
- - org.gradle.testsuite.target.name = test
- - org.gradle.testsuite.type = unit-test
- - org.gradle.verificationtype = jacoco-coverage
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test
+ - org.gradle.verificationtype = jacoco-coverage
Artifacts
- $resultsExecPath (artifactType = binary)
""")
@@ -180,8 +178,6 @@
testing {
suites {
integrationTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
-
dependencies {
implementation project()
}
@@ -198,16 +194,14 @@
--------------------------------------------------
Variant coverageDataElementsForIntegrationTest (i)
--------------------------------------------------
-Binary data file containing results of Jacoco test coverage reporting for the integrationTest Test Suite's integrationTest target.
+Binary results containing Jacoco test coverage for all targets in the 'integrationTest' Test Suite.
Capabilities
- :Test:unspecified (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = integrationTest
- - org.gradle.testsuite.target.name = integrationTest
- - org.gradle.testsuite.type = integration-test
- - org.gradle.verificationtype = jacoco-coverage
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = integrationTest
+ - org.gradle.verificationtype = jacoco-coverage
Artifacts
- $resultsExecPath (artifactType = binary)""")
diff --git a/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoCoverageReport.java b/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoCoverageReport.java
index d9ed386..b1b3ed1 100644
--- a/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoCoverageReport.java
+++ b/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoCoverageReport.java
@@ -38,9 +38,12 @@ public interface JacocoCoverageReport extends ReportSpec {
TaskProvider<JacocoReport> getReportTask();
/**
- * Contains a value representing the type of test suite this task belongs to. See static constants on {@link org.gradle.api.attributes.TestSuiteType} for examples.
+ * Contains the name of the test suite in target projects that this report will aggregate.
*
- * @return this report's test type
+ * @return the name of the suite that this report will aggregate.
+ *
+ * @since 8.13
*/
- Property<String> getTestType();
+ Property<String> getTestSuiteName();
+
}
diff --git a/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoPlugin.java b/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoPlugin.java
index 5f29e9f..e0bcaab 100644
--- a/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoPlugin.java
+++ b/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoPlugin.java
@@ -16,19 +16,17 @@
package org.gradle.testing.jacoco.plugins;
import org.apache.commons.lang.StringUtils;
-import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer;
+import org.gradle.api.NamedDomainObjectProvider;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
+import org.gradle.api.artifacts.ConsumableConfiguration;
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.attributes.Category;
import org.gradle.api.attributes.TestSuiteName;
-import org.gradle.api.attributes.TestSuiteTargetName;
-import org.gradle.api.attributes.TestSuiteType;
import org.gradle.api.attributes.VerificationType;
import org.gradle.api.file.DirectoryProperty;
-import org.gradle.api.internal.artifacts.configurations.ConfigurationRolesForMigration;
import org.gradle.api.internal.artifacts.configurations.RoleBasedConfigurationContainerInternal;
import org.gradle.api.internal.file.FileOperations;
import org.gradle.api.internal.project.ProjectInternal;
@@ -37,7 +35,7 @@
import org.gradle.api.plugins.JvmTestSuitePlugin;
import org.gradle.api.plugins.ReportingBasePlugin;
import org.gradle.api.plugins.jvm.JvmTestSuite;
-import org.gradle.api.plugins.jvm.JvmTestSuiteTarget;
+import org.gradle.api.provider.Provider;
import org.gradle.api.reporting.DirectoryReport;
import org.gradle.api.reporting.Report;
import org.gradle.api.reporting.ReportingExtension;
@@ -48,13 +46,13 @@
import org.gradle.internal.jacoco.JacocoAgentJar;
import org.gradle.internal.reflect.Instantiator;
import org.gradle.language.base.plugins.LifecycleBasePlugin;
-import org.gradle.testing.base.TestSuite;
import org.gradle.testing.base.TestingExtension;
import org.gradle.testing.jacoco.tasks.JacocoBase;
import org.gradle.testing.jacoco.tasks.JacocoCoverageVerification;
import org.gradle.testing.jacoco.tasks.JacocoReport;
import javax.inject.Inject;
+import java.io.File;
import static org.gradle.api.internal.lambdas.SerializableLambdas.action;
@@ -74,7 +72,6 @@ public abstract class JacocoPlugin implements Plugin<Project> {
public static final String AGENT_CONFIGURATION_NAME = "jacocoAgent";
public static final String ANT_CONFIGURATION_NAME = "jacocoAnt";
public static final String PLUGIN_EXTENSION_NAME = "jacoco";
- private static final String COVERAGE_DATA_ELEMENTS_VARIANT_PREFIX = "coverageDataElementsFor";
private final Instantiator instantiator;
private ProjectInternal project;
@@ -103,36 +100,51 @@ public void apply(Project project) {
configureCoverageDataElementsVariants(project);
}
- private void configureCoverageDataElementsVariants(Project project) {
+ private static void configureCoverageDataElementsVariants(Project project) {
project.getPlugins().withType(JvmTestSuitePlugin.class, p -> {
- final TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
- final ExtensiblePolymorphicDomainObjectContainer<TestSuite> testSuites = testing.getSuites();
+ TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
- testSuites.withType(JvmTestSuite.class).configureEach(suite -> {
+ testing.getSuites().withType(JvmTestSuite.class).configureEach(suite -> {
+ // TODO: Eventually, we want a jacoco results variant for each target, but cannot do so now because:
+ // 1. Targets need a way to uniquely identify themselves via attributes. We do not have an API to describe
+ // a target using attributes yet.
+ // 2. If a suite has multiple jacoco results variants, we get ambiguity when resolving the jacoco results variant.
+ // We should add a feature to dependency management allowing ArtifactView to select multiple variants from the target component.
+ NamedDomainObjectProvider<ConsumableConfiguration> jacocoResultsVariant = createCoverageDataVariant((ProjectInternal) project, suite);
+
suite.getTargets().configureEach(target -> {
- createCoverageDataVariant((ProjectInternal) project, suite, target);
+ jacocoResultsVariant.configure(variant -> {
+ Provider<File> resultsDir = target.getTestTask().map(task ->
+ task.getExtensions().getByType(JacocoTaskExtension.class).getDestinationFile()
+ );
+
+ variant.getOutgoing().artifact(
+ resultsDir,
+ artifact -> artifact.setType(ArtifactTypeDefinition.BINARY_DATA_TYPE)
+ );
+ });
});
+
});
+
});
}
- private void createCoverageDataVariant(ProjectInternal project, JvmTestSuite suite, JvmTestSuiteTarget target) {
- @SuppressWarnings("deprecation") final Configuration variant = project.getConfigurations().migratingUnlocked(COVERAGE_DATA_ELEMENTS_VARIANT_PREFIX + StringUtils.capitalize(target.getName()), ConfigurationRolesForMigration.CONSUMABLE_DEPENDENCY_SCOPE_TO_CONSUMABLE);
- variant.setDescription("Binary data file containing results of Jacoco test coverage reporting for the " + suite.getName() + " Test Suite's " + target.getName() + " target.");
- variant.setVisible(false);
+ private static NamedDomainObjectProvider<ConsumableConfiguration> createCoverageDataVariant(ProjectInternal project, JvmTestSuite suite) {
+ String variantName = String.format("coverageDataElementsFor%s", StringUtils.capitalize(suite.getName()));
- final ObjectFactory objects = project.getObjects();
- variant.attributes(attributes -> {
- attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
- attributes.attribute(TestSuiteName.TEST_SUITE_NAME_ATTRIBUTE, objects.named(TestSuiteName.class, suite.getName()));
- attributes.attribute(TestSuiteTargetName.TEST_SUITE_TARGET_NAME_ATTRIBUTE, objects.named(TestSuiteTargetName.class, target.getName()));
- attributes.attributeProvider(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE, suite.getTestType().map(tt -> objects.named(TestSuiteType.class, tt)));
- attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.JACOCO_RESULTS));
- });
+ return project.getConfigurations().consumable(variantName, conf -> {
+ conf.setDescription("Binary results containing Jacoco test coverage for all targets in the '" + suite.getName() + "' Test Suite.");
- variant.getOutgoing().artifact(target.getTestTask().map(task -> task.getExtensions().getByType(JacocoTaskExtension.class).getDestinationFile()), artifact -> {
- artifact.setType(ArtifactTypeDefinition.BINARY_DATA_TYPE);
- artifact.builtBy(target.getTestTask());
+ ObjectFactory objects = project.getObjects();
+ conf.attributes(attributes -> {
+ attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
+ attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.JACOCO_RESULTS));
+
+ // TODO: Allow targets to define attributes uniquely identifying themselves.
+ // Then, create a jacoco results variant for each target instead of each suite.
+ attributes.attribute(TestSuiteName.TEST_SUITE_NAME_ATTRIBUTE, objects.named(TestSuiteName.class, suite.getName()));
+ });
});
}
diff --git a/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoReportAggregationPlugin.java b/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoReportAggregationPlugin.java
index cac2075..0cef0b3 100644
--- a/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoReportAggregationPlugin.java
+++ b/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoReportAggregationPlugin.java
@@ -28,7 +28,7 @@
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.attributes.Category;
import org.gradle.api.attributes.LibraryElements;
-import org.gradle.api.attributes.TestSuiteType;
+import org.gradle.api.attributes.TestSuiteName;
import org.gradle.api.attributes.VerificationType;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.model.ObjectFactory;
@@ -109,7 +109,7 @@ public void apply(Project project) {
view.componentFilter(projectComponent());
view.attributes(attributes -> {
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
- attributes.attributeProvider(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE, report.getTestType().map(tt -> objects.named(TestSuiteType.class, tt)));
+ attributes.attributeProvider(TestSuiteName.TEST_SUITE_NAME_ATTRIBUTE, report.getTestSuiteName().map(tt -> objects.named(TestSuiteName.class, tt)));
attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.JACOCO_RESULTS));
attributes.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.BINARY_DATA_TYPE);
});
@@ -129,7 +129,7 @@ public void apply(Project project) {
testSuites.withType(JvmTestSuite.class).all(testSuite -> {
reporting.getReports().create(testSuite.getName() + "CodeCoverageReport", JacocoCoverageReport.class, report -> {
- report.getTestType().convention(testSuite.getTestType());
+ report.getTestSuiteName().convention(testSuite.getName());
});
});
});
diff --git a/platforms/jvm/plugins-jvm-test-suite/build.gradle.kts b/platforms/jvm/plugins-jvm-test-suite/build.gradle.kts
index fcfa09d..0366b31 100644
--- a/platforms/jvm/plugins-jvm-test-suite/build.gradle.kts
+++ b/platforms/jvm/plugins-jvm-test-suite/build.gradle.kts
@@ -39,14 +39,10 @@
api(libs.inject)
- implementation(projects.core)
implementation(projects.logging)
implementation(projects.pluginsJavaBase)
implementation(projects.testingBase)
- implementation(libs.commonsLang)
-
- implementation(libs.ant)
implementation(libs.guava)
integTestDistributionRuntimeOnly(projects.distributionsJvm)
diff --git a/platforms/jvm/plugins-jvm-test-suite/src/integTest/groovy/org/gradle/api/plugins/JvmTestSuitePluginIntegrationTest.groovy b/platforms/jvm/plugins-jvm-test-suite/src/integTest/groovy/org/gradle/api/plugins/JvmTestSuitePluginIntegrationTest.groovy
index 8b6263b..a45ca4a 100644
--- a/platforms/jvm/plugins-jvm-test-suite/src/integTest/groovy/org/gradle/api/plugins/JvmTestSuitePluginIntegrationTest.groovy
+++ b/platforms/jvm/plugins-jvm-test-suite/src/integTest/groovy/org/gradle/api/plugins/JvmTestSuitePluginIntegrationTest.groovy
@@ -47,16 +47,14 @@
--------------------------------------------------
Variant testResultsElementsForTest (i)
--------------------------------------------------
-Directory containing binary results of running tests for the test Test Suite's test target.
+Binary results obtained from running all targets in the 'test' Test Suite.
Capabilities
- :Test:unspecified (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test
- - org.gradle.testsuite.target.name = test
- - org.gradle.testsuite.type = unit-test
- - org.gradle.verificationtype = test-results
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test
+ - org.gradle.verificationtype = test-results
Artifacts
- $resultsPath (artifactType = directory)""".stripIndent())
@@ -75,8 +73,6 @@
testing {
suites {
integrationTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
-
dependencies {
implementation project()
}
@@ -93,16 +89,14 @@
--------------------------------------------------
Variant testResultsElementsForIntegrationTest (i)
--------------------------------------------------
-Directory containing binary results of running tests for the integrationTest Test Suite's integrationTest target.
+Binary results obtained from running all targets in the 'integrationTest' Test Suite.
Capabilities
- :Test:unspecified (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = integrationTest
- - org.gradle.testsuite.target.name = integrationTest
- - org.gradle.testsuite.type = integration-test
- - org.gradle.verificationtype = test-results
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = integrationTest
+ - org.gradle.verificationtype = test-results
Artifacts
- $resultsPath (artifactType = directory)""".stripIndent())
@@ -110,7 +104,7 @@
hasIncubatingLegend()
}
- def "Test suites in different projects can use same test type"() {
+ def "Test suites in different projects can have the same name"() {
def subADir = createDir("subA")
subADir.file("build.gradle") << """
plugins {
@@ -121,9 +115,7 @@
testing {
suites {
- integrationTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
- }
+ integrationTest(JvmTestSuite)
}
}""".stripIndent()
@@ -137,9 +129,7 @@
testing {
suites {
- integrationTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
- }
+ integrationTest(JvmTestSuite)
}
}""".stripIndent()
@@ -161,8 +151,4 @@
expect:
succeeds('allIntegrationTests')
}
-
- private String systemFilePath(String path) {
- return path.replace('/', File.separator)
- }
}
diff --git a/platforms/jvm/plugins-jvm-test-suite/src/integTest/groovy/org/gradle/testing/testsuites/TestSuitesMultiTargetIntegrationTest.groovy b/platforms/jvm/plugins-jvm-test-suite/src/integTest/groovy/org/gradle/testing/testsuites/TestSuitesMultiTargetIntegrationTest.groovy
index e1115c9..518e998 100644
--- a/platforms/jvm/plugins-jvm-test-suite/src/integTest/groovy/org/gradle/testing/testsuites/TestSuitesMultiTargetIntegrationTest.groovy
+++ b/platforms/jvm/plugins-jvm-test-suite/src/integTest/groovy/org/gradle/testing/testsuites/TestSuitesMultiTargetIntegrationTest.groovy
@@ -127,8 +127,7 @@
failure.assertThatCause(containsNormalizedString("Cannot add task 'test' as a task with that name already exists."))
}
- // currently not supported, variants are ambiguous without further information
- def "reports of multiple targets cannot be aggregated"() {
+ def "reports of multiple targets can be aggregated"() {
setupBasicTestingProject(['test-report-aggregation'])
buildFile << """
testing {
@@ -150,11 +149,10 @@
"""
when:
- withInstallations(Jvm.current(), otherJvm).fails("testAggregateTestReport")
+ withInstallations(Jvm.current(), otherJvm).succeeds("testAggregateTestReport")
then:
- failure.assertThatCause(containsNormalizedString("There are several available matching variants of root project :"))
- failure.assertThatCause(containsNormalizedString("The only attribute distinguishing these variants is 'org.gradle.testsuite.target.name'. Add this attribute to the consumer's configuration to resolve the ambiguity:"))
+ result.assertTaskExecuted(":testAggregateTestReport")
}
def "reports of multiple targets can be aggregated if variant information is specified"() {
diff --git a/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/JvmTestSuitePlugin.java b/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/JvmTestSuitePlugin.java
index 14e62e6..fdd4dba 100644
--- a/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/JvmTestSuitePlugin.java
+++ b/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/JvmTestSuitePlugin.java
@@ -16,34 +16,15 @@
package org.gradle.api.plugins;
-import org.apache.commons.lang.StringUtils;
-import org.apache.tools.ant.BuildException;
-import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer;
import org.gradle.api.Incubating;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
-import org.gradle.api.artifacts.Configuration;
-import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
-import org.gradle.api.attributes.Category;
-import org.gradle.api.attributes.TestSuiteName;
-import org.gradle.api.attributes.TestSuiteTargetName;
-import org.gradle.api.attributes.TestSuiteType;
-import org.gradle.api.attributes.VerificationType;
-import org.gradle.api.internal.project.ProjectInternal;
-import org.gradle.api.model.ObjectFactory;
import org.gradle.api.plugins.jvm.JvmTestSuite;
-import org.gradle.api.plugins.jvm.JvmTestSuiteTarget;
import org.gradle.api.plugins.jvm.internal.DefaultJvmTestSuite;
-import org.gradle.api.tasks.testing.AbstractTestTask;
import org.gradle.api.tasks.testing.Test;
import org.gradle.internal.deprecation.DeprecationLogger;
-import org.gradle.testing.base.TestSuite;
import org.gradle.testing.base.TestingExtension;
import org.gradle.testing.base.plugins.TestSuiteBasePlugin;
-import org.gradle.util.internal.TextUtil;
-
-import java.util.HashMap;
-import java.util.Map;
/**
* A {@link org.gradle.api.Plugin} that adds extensions for declaring, compiling and running {@link JvmTestSuite}s.
@@ -61,18 +42,16 @@
@Incubating
public abstract class JvmTestSuitePlugin implements Plugin<Project> {
public static final String DEFAULT_TEST_SUITE_NAME = "test";
- private static final String TEST_RESULTS_ELEMENTS_VARIANT_PREFIX = "testResultsElementsFor";
-
- private final Map<String, TestSuite> testTypesInUse = new HashMap<>(2); // Assume limited initial amount of test types/project, just unit and integration
@Override
public void apply(Project project) {
project.getPluginManager().apply(TestSuiteBasePlugin.class);
project.getPluginManager().apply(JavaBasePlugin.class);
+
JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension.class);
+
TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
- ExtensiblePolymorphicDomainObjectContainer<TestSuite> testSuites = testing.getSuites();
- testSuites.registerBinding(JvmTestSuite.class, DefaultJvmTestSuite.class);
+ testing.getSuites().registerBinding(JvmTestSuite.class, DefaultJvmTestSuite.class);
project.getTasks().withType(Test.class).configureEach(test -> {
// The test task may have already been created but the test sourceSet may not exist yet.
@@ -96,8 +75,7 @@ public void apply(Project project) {
test.getModularity().getInferModulePath().convention(java.getModularity().getInferModulePath());
});
- testSuites.withType(JvmTestSuite.class).all(testSuite -> {
- testSuite.getTestType().convention(getDefaultTestType(testSuite));
+ testing.getSuites().withType(JvmTestSuite.class).all(testSuite -> {
testSuite.getTargets().all(target -> {
target.getTestTask().configure(test -> {
test.getConventionMapping().map("testClassesDirs", () -> testSuite.getSources().getOutput().getClassesDirs());
@@ -105,50 +83,6 @@ public void apply(Project project) {
});
});
});
-
- configureTestDataElementsVariants((ProjectInternal) project);
}
- private String getDefaultTestType(JvmTestSuite testSuite) {
- return DEFAULT_TEST_SUITE_NAME.equals(testSuite.getName()) ? TestSuiteType.UNIT_TEST : TextUtil.camelToKebabCase(testSuite.getName());
- }
-
- private void configureTestDataElementsVariants(ProjectInternal project) {
- final TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
- final ExtensiblePolymorphicDomainObjectContainer<TestSuite> testSuites = testing.getSuites();
-
- testSuites.withType(JvmTestSuite.class).configureEach(suite -> {
- suite.getTargets().configureEach(target -> {
- addTestResultsVariant(project, suite, target);
- });
- });
- }
-
- private void addTestResultsVariant(ProjectInternal project, JvmTestSuite suite, JvmTestSuiteTarget target) {
- final Configuration variant = project.getConfigurations().consumable(TEST_RESULTS_ELEMENTS_VARIANT_PREFIX + StringUtils.capitalize(target.getName())).get();
- variant.setDescription("Directory containing binary results of running tests for the " + suite.getName() + " Test Suite's " + target.getName() + " target.");
- variant.setVisible(false);
-
- final ObjectFactory objects = project.getObjects();
- variant.attributes(attributes -> {
- attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
- attributes.attribute(TestSuiteName.TEST_SUITE_NAME_ATTRIBUTE, objects.named(TestSuiteName.class, suite.getName()));
- attributes.attribute(TestSuiteTargetName.TEST_SUITE_TARGET_NAME_ATTRIBUTE, objects.named(TestSuiteTargetName.class, target.getName()));
- attributes.attributeProvider(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE, suite.getTestType().map(tt -> createNamedTestTypeAndVerifyUniqueness(project, suite, tt)));
- attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.TEST_RESULTS));
- });
-
- variant.getOutgoing().artifact(
- target.getTestTask().flatMap(AbstractTestTask::getBinaryResultsDirectory),
- artifact -> artifact.setType(ArtifactTypeDefinition.DIRECTORY_TYPE)
- );
- }
-
- private TestSuiteType createNamedTestTypeAndVerifyUniqueness(Project project, TestSuite suite, String tt) {
- final TestSuite other = testTypesInUse.putIfAbsent(tt, suite);
- if (null != other && other != suite) {
- throw new BuildException("Could not configure suite: '" + suite.getName() + "'. Another test suite: '" + other.getName() + "' uses the type: '" + tt + "' and has already been configured in project: '" + project.getName() + "'.");
- }
- return project.getObjects().named(TestSuiteType.class, tt);
- }
}
diff --git a/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/jvm/JvmTestSuite.java b/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/jvm/JvmTestSuite.java
index 628255a..0946f9d 100644
--- a/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/jvm/JvmTestSuite.java
+++ b/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/jvm/JvmTestSuite.java
@@ -20,8 +20,6 @@
import org.gradle.api.Buildable;
import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer;
import org.gradle.api.Incubating;
-import org.gradle.api.attributes.TestSuiteType;
-import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Nested;
import org.gradle.api.tasks.SourceSet;
@@ -74,16 +72,6 @@ public interface JvmTestSuite extends TestSuite, Buildable {
ExtensiblePolymorphicDomainObjectContainer<? extends JvmTestSuiteTarget> getTargets();
/**
- * Get the test type for this test suite.
- *
- * Defaults to the value of the {@code UNIT_TEST} constant defined in {@link TestSuiteType} for the built-in test suite, and to the dash-case name of the
- * test suite for custom test suites. Test suite types must be unique across all test suites within a project.
- *
- * @since 7.4
- */
- Property<String> getTestType();
-
- /**
* Use the <a href="https://junit.org/junit5/docs/current/user-guide/">JUnit Jupiter</a> testing framework.
*
* <p>
diff --git a/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/jvm/internal/DefaultJvmTestSuiteTarget.java b/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/jvm/internal/DefaultJvmTestSuiteTarget.java
index 51a57b0..e089937 100644
--- a/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/jvm/internal/DefaultJvmTestSuiteTarget.java
+++ b/platforms/jvm/plugins-jvm-test-suite/src/main/java/org/gradle/api/plugins/jvm/internal/DefaultJvmTestSuiteTarget.java
@@ -17,12 +17,15 @@
package org.gradle.api.plugins.jvm.internal;
import org.gradle.api.Buildable;
+import org.gradle.api.file.Directory;
import org.gradle.api.internal.tasks.TaskDependencyFactory;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.jvm.JvmTestSuiteTarget;
+import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskDependency;
import org.gradle.api.tasks.TaskProvider;
+import org.gradle.api.tasks.testing.AbstractTestTask;
import org.gradle.api.tasks.testing.Test;
import org.gradle.util.internal.GUtil;
@@ -56,6 +59,11 @@ public TaskProvider<Test> getTestTask() {
}
@Override
+ public Provider<Directory> getBinaryTestResultsDirectory() {
+ return testTask.flatMap(AbstractTestTask::getBinaryResultsDirectory);
+ }
+
+ @Override
public TaskDependency getBuildDependencies() {
return taskDependencyFactory.visitingDependencies(context -> context.add(getTestTask()));
}
diff --git a/platforms/jvm/plugins-test-report-aggregation/src/integTest/groovy/org/gradle/api/plugins/TestReportAggregationPluginIntegrationTest.groovy b/platforms/jvm/plugins-test-report-aggregation/src/integTest/groovy/org/gradle/api/plugins/TestReportAggregationPluginIntegrationTest.groovy
index d2bc85a..cc48641 100644
--- a/platforms/jvm/plugins-test-report-aggregation/src/integTest/groovy/org/gradle/api/plugins/TestReportAggregationPluginIntegrationTest.groovy
+++ b/platforms/jvm/plugins-test-report-aggregation/src/integTest/groovy/org/gradle/api/plugins/TestReportAggregationPluginIntegrationTest.groovy
@@ -170,7 +170,7 @@
def applicationTestResults = new HtmlTestExecutionResult(testDirectory.file('application'))
applicationTestResults.assertTestClassesExecuted('application.AdderTest')
- def aggregatedResults = new HtmlTestExecutionResult(testDirectory, "application/build/reports/tests/unit-test/aggregated-results")
+ def aggregatedResults = new HtmlTestExecutionResult(testDirectory, "application/build/reports/tests/test/aggregated-results")
aggregatedResults.assertTestClassesExecuted("application.AdderTest", "direct.MultiplierTest", "transitive.PowerizeTest")
}
@@ -180,7 +180,6 @@
testing {
suites {
integTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
useJUnit()
dependencies {
implementation project()
@@ -195,7 +194,6 @@
testing {
suites {
integTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
useJUnit()
dependencies {
implementation project(':transitive') // necessary to access Divisor when compiling test
@@ -275,10 +273,10 @@
def applicationIntegTestResults = new HtmlTestExecutionResult(testDirectory.file('application'), 'build/reports/tests/integTest')
applicationIntegTestResults.assertTestClassesExecuted('application.DivTest')
- def aggregatedTestResults = new HtmlTestExecutionResult(testDirectory, 'application/build/reports/tests/unit-test/aggregated-results')
+ def aggregatedTestResults = new HtmlTestExecutionResult(testDirectory, 'application/build/reports/tests/test/aggregated-results')
aggregatedTestResults.assertTestClassesExecuted('application.AdderTest', 'direct.MultiplierTest', 'transitive.PowerizeTest')
- def aggregatedIntegTestResults = new HtmlTestExecutionResult(testDirectory, 'application/build/reports/tests/integration-test/aggregated-results')
+ def aggregatedIntegTestResults = new HtmlTestExecutionResult(testDirectory, 'application/build/reports/tests/integTest/aggregated-results')
aggregatedIntegTestResults.assertTestClassesExecuted('transitive.ModTest', 'application.DivTest')
}
@@ -295,7 +293,7 @@
reporting {
reports {
testAggregateTestReport(AggregateTestReport) {
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
@@ -314,7 +312,7 @@
def applicationTestResults = new HtmlTestExecutionResult(testDirectory.file('application'))
applicationTestResults.assertTestClassesExecuted('application.AdderTest')
- def aggregatedTestResults = new HtmlTestExecutionResult(testDirectory, 'build/reports/tests/unit-test/aggregated-results')
+ def aggregatedTestResults = new HtmlTestExecutionResult(testDirectory, 'build/reports/tests/test/aggregated-results')
aggregatedTestResults.assertTestClassesExecuted('application.AdderTest', 'direct.MultiplierTest', 'transitive.PowerizeTest')
}
@@ -331,7 +329,7 @@
reporting {
reports {
testAggregateTestReport(AggregateTestReport) {
- testType = TestSuiteType.UNIT_TEST
+ testSuiteName = "test"
}
}
}
@@ -343,7 +341,7 @@
succeeds(':testAggregateTestReport')
then:
- def aggregatedTestResults = new HtmlTestExecutionResult(testDirectory, 'build/reports/tests/unit-test/aggregated-results')
+ def aggregatedTestResults = new HtmlTestExecutionResult(testDirectory, 'build/reports/tests/test/aggregated-results')
aggregatedTestResults.assertTestClassesExecuted('application.AdderTest', 'direct.MultiplierTest')
}
@@ -373,7 +371,7 @@
.assertThatCause(startsWith("There were failing tests"))
result.assertTaskNotExecuted(':application:testAggregateTestReport')
- file("application/build/reports/tests/unit-test/aggregated-results").assertDoesNotExist()
+ file("application/build/reports/tests/test/aggregated-results").assertDoesNotExist()
}
def 'test verification failure creates aggregated report with --continue flag'() {
@@ -412,7 +410,7 @@
def applicationTestResults = new HtmlTestExecutionResult(testDirectory.file('application'))
applicationTestResults.assertTestClassesExecuted('application.AdderTest')
- def aggregatedResults = new HtmlTestExecutionResult(testDirectory, "application/build/reports/tests/unit-test/aggregated-results")
+ def aggregatedResults = new HtmlTestExecutionResult(testDirectory, "application/build/reports/tests/test/aggregated-results")
aggregatedResults.assertTestClassesExecuted("application.AdderTest", "direct.MultiplierTest", "transitive.PowerizeTest")
}
@@ -439,7 +437,7 @@
then:
result.assertTaskExecuted(":application:testAggregateTestReport")
- def aggregatedResults = new HtmlTestExecutionResult(testDirectory, "application/build/non-default-location/unit-test/aggregated-results")
+ def aggregatedResults = new HtmlTestExecutionResult(testDirectory, "application/build/non-default-location/test/aggregated-results")
aggregatedResults.assertTestClassesExecuted("application.AdderTest", "direct.MultiplierTest", "transitive.PowerizeTest")
}
@@ -473,7 +471,7 @@
result.assertTaskExecuted(":transitive:test")
result.assertTaskNotExecuted(":application:testAggregateTestReport")
- file("application/build/reports/tests/unit-test/aggregated-results").assertDoesNotExist()
+ file("application/build/reports/tests/test/aggregated-results").assertDoesNotExist()
}
@@ -508,87 +506,7 @@
result.assertTaskNotExecuted(":transitive:test")
result.assertTaskNotExecuted(":application:testAggregateTestReport")
- file("application/build/reports/tests/unit-test/aggregated-results").assertDoesNotExist()
- }
-
- def "Only one suite with a given test type allowed per project"() {
- file("src/primaryIntTest/java/com/example/FooTest.java") << "package com.example; class FooTest {}"
- file("src/secondaryIntTest/java/com/example/FooTest.java") << "package com.example; class FooTest {}"
-
- file("application/build.gradle") << """
- apply plugin: 'org.gradle.test-report-aggregation'
- """
- file("transitive/build.gradle") << """
- testing {
- suites {
- primaryIntTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
- }
-
- secondaryIntTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
- }
- }
- }
- """
-
- expect:
- fails(':application:testAggregateTestReport')
- result.assertHasErrorOutput("Could not configure suite: 'secondaryIntTest'. Another test suite: 'primaryIntTest' uses the type: 'integration-test' and has already been configured in project: 'transitive'.")
- }
-
- def "Only one suite with a given test type allowed per project (including the built-in test suite)"() {
- file("src/test/java/com/example/FooTest.java") << "package com.example; class FooTest {}"
- file("src/secondaryTest/java/com/example/FooTest.java") << "package com.example; class FooTest {}"
-
- file("application/build.gradle") << """
- apply plugin: 'org.gradle.test-report-aggregation'
- """
- file("transitive/build.gradle") << """
- plugins {
- id("java-library")
- }
-
- testing {
- suites {
- secondaryTest(JvmTestSuite) {
- testType = TestSuiteType.UNIT_TEST
- }
- }
- }
- """
-
- expect:
- fails(':application:testAggregateTestReport')
- result.assertHasErrorOutput("Could not configure suite: 'test'. Another test suite: 'secondaryTest' uses the type: 'unit-test' and has already been configured in project: 'transitive'.")
- }
-
- def "Only one suite with a given test type allowed per project (using the default type of one suite and explicitly setting the other)"() {
- file("src/integrationTest/java/com/example/FooTest.java") << "package com.example; class FooTest {}"
- file("src/secondaryIntegrationTest/java/com/example/FooTest.java") << "package com.example; class FooTest {}"
-
- file("application/build.gradle") << """
- apply plugin: 'org.gradle.test-report-aggregation'
- """
- file("transitive/build.gradle") << """
- plugins {
- id("java-library")
- }
-
- testing {
- suites {
- integrationTest(JvmTestSuite)
-
- secondaryIntegrationTest(JvmTestSuite) {
- testType = TestSuiteType.INTEGRATION_TEST
- }
- }
- }
- """
-
- expect:
- fails(':application:testAggregateTestReport')
- result.assertHasErrorOutput("Could not configure suite: 'secondaryIntegrationTest'. Another test suite: 'integrationTest' uses the type: 'integration-test' and has already been configured in project: 'transitive'.")
+ file("application/build/reports/tests/test/aggregated-results").assertDoesNotExist()
}
@Issue("https://github.com/gradle/gradle/issues/29820")
diff --git a/platforms/jvm/plugins-test-report-aggregation/src/main/java/org/gradle/api/plugins/TestReportAggregationPlugin.java b/platforms/jvm/plugins-test-report-aggregation/src/main/java/org/gradle/api/plugins/TestReportAggregationPlugin.java
index 4c5b8c5..aebedf7 100644
--- a/platforms/jvm/plugins-test-report-aggregation/src/main/java/org/gradle/api/plugins/TestReportAggregationPlugin.java
+++ b/platforms/jvm/plugins-test-report-aggregation/src/main/java/org/gradle/api/plugins/TestReportAggregationPlugin.java
@@ -24,7 +24,7 @@
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.component.ProjectComponentIdentifier;
import org.gradle.api.attributes.Category;
-import org.gradle.api.attributes.TestSuiteType;
+import org.gradle.api.attributes.TestSuiteName;
import org.gradle.api.attributes.VerificationType;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
@@ -96,13 +96,13 @@ public void apply(Project project) {
view.componentFilter(spec(id -> id instanceof ProjectComponentIdentifier));
view.attributes(attributes -> {
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
- attributes.attributeProvider(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE, report.getTestType().map(tt -> objects.named(TestSuiteType.class, tt)));
+ attributes.attributeProvider(TestSuiteName.TEST_SUITE_NAME_ATTRIBUTE, report.getTestSuiteName().map(tt -> objects.named(TestSuiteName.class, tt)));
attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.TEST_RESULTS));
});
}).getFiles();
task.getTestResults().from(testResults);
- task.getDestinationDirectory().convention(testReportDirectory.dir(report.getTestType().map(tt -> tt + "/aggregated-results")));
+ task.getDestinationDirectory().convention(testReportDirectory.dir(report.getTestSuiteName().map(tt -> tt + "/aggregated-results")));
});
});
@@ -116,7 +116,7 @@ public void apply(Project project) {
testSuites.withType(JvmTestSuite.class).all(testSuite -> {
reporting.getReports().create(testSuite.getName() + "AggregateTestReport", AggregateTestReport.class, report -> {
- report.getTestType().convention(testSuite.getTestType());
+ report.getTestSuiteName().convention(testSuite.getName());
});
});
});
diff --git a/platforms/jvm/testing-jvm/src/main/java/org/gradle/api/tasks/testing/AggregateTestReport.java b/platforms/jvm/testing-jvm/src/main/java/org/gradle/api/tasks/testing/AggregateTestReport.java
index e05b43d..8dafaaf 100644
--- a/platforms/jvm/testing-jvm/src/main/java/org/gradle/api/tasks/testing/AggregateTestReport.java
+++ b/platforms/jvm/testing-jvm/src/main/java/org/gradle/api/tasks/testing/AggregateTestReport.java
@@ -37,9 +37,11 @@ public interface AggregateTestReport extends ReportSpec {
TaskProvider<TestReport> getReportTask();
/**
- * Contains a value representing the type of test suite this task belongs to. See static constants on {@link org.gradle.api.attributes.TestSuiteType} for examples.
+ * Contains the name of the test suite in target projects that this report will aggregate.
*
- * @return this report's test type
+ * @return the name of the suite that this report will aggregate.
+ *
+ * @since 8.13
*/
- Property<String> getTestType();
+ Property<String> getTestSuiteName();
}
diff --git a/platforms/software/test-suites-base/build.gradle.kts b/platforms/software/test-suites-base/build.gradle.kts
index 01ee5ec..df1b1c7 100644
--- a/platforms/software/test-suites-base/build.gradle.kts
+++ b/platforms/software/test-suites-base/build.gradle.kts
@@ -18,6 +18,8 @@
api(libs.inject)
+ implementation(libs.commonsLang3)
+
testImplementation(testFixtures(projects.baseServices))
testImplementation(testFixtures(projects.core))
testImplementation(testFixtures(projects.logging))
diff --git a/platforms/software/test-suites-base/src/main/java/org/gradle/testing/base/TestSuiteTarget.java b/platforms/software/test-suites-base/src/main/java/org/gradle/testing/base/TestSuiteTarget.java
index d9fed1e..b0882fc 100644
--- a/platforms/software/test-suites-base/src/main/java/org/gradle/testing/base/TestSuiteTarget.java
+++ b/platforms/software/test-suites-base/src/main/java/org/gradle/testing/base/TestSuiteTarget.java
@@ -17,6 +17,8 @@
package org.gradle.testing.base;
import org.gradle.api.Incubating;
+import org.gradle.api.file.Directory;
+import org.gradle.api.provider.Provider;
/**
* Base test suite target.
@@ -27,4 +29,14 @@
*/
@Incubating
public interface TestSuiteTarget {
+
+ /**
+ * The directory containing the binary results produced by executing this test suite target.
+ *
+ * @return the binary results directory
+ *
+ * @since 8.13
+ */
+ Provider<Directory> getBinaryTestResultsDirectory();
+
}
diff --git a/platforms/software/test-suites-base/src/main/java/org/gradle/testing/base/plugins/TestSuiteBasePlugin.java b/platforms/software/test-suites-base/src/main/java/org/gradle/testing/base/plugins/TestSuiteBasePlugin.java
index 1193c71..7b6bf71 100644
--- a/platforms/software/test-suites-base/src/main/java/org/gradle/testing/base/plugins/TestSuiteBasePlugin.java
+++ b/platforms/software/test-suites-base/src/main/java/org/gradle/testing/base/plugins/TestSuiteBasePlugin.java
@@ -16,9 +16,18 @@
package org.gradle.testing.base.plugins;
+import org.apache.commons.lang3.StringUtils;
import org.gradle.api.Incubating;
+import org.gradle.api.NamedDomainObjectProvider;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
+import org.gradle.api.artifacts.ConsumableConfiguration;
+import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
+import org.gradle.api.attributes.Category;
+import org.gradle.api.attributes.TestSuiteName;
+import org.gradle.api.attributes.VerificationType;
+import org.gradle.api.model.ObjectFactory;
+import org.gradle.testing.base.TestSuite;
import org.gradle.testing.base.TestingExtension;
import org.gradle.testing.base.internal.DefaultTestingExtension;
@@ -29,8 +38,45 @@
*/
@Incubating
public abstract class TestSuiteBasePlugin implements Plugin<Project> {
+
@Override
public void apply(Project project) {
- project.getExtensions().create(TestingExtension.class, "testing", DefaultTestingExtension.class);
+ TestingExtension testing = project.getExtensions().create(TestingExtension.class, "testing", DefaultTestingExtension.class);
+
+ testing.getSuites().configureEach(suite -> {
+ // TODO: Eventually, we want a test results variant for each target, but cannot do so now because:
+ // 1. Targets need a way to uniquely identify themselves via attributes. We do not have an API to describe
+ // a target using attributes yet.
+ // 2. If a suite has multiple test results variants, we get ambiguity when resolving the test results variant.
+ // We should add a feature to dependency management allowing ArtifactView to select multiple variants from the target component.
+ NamedDomainObjectProvider<ConsumableConfiguration> testResultsVariant = addTestResultsVariant(project, suite);
+
+ suite.getTargets().configureEach(target -> {
+ testResultsVariant.configure(variant -> {
+ variant.getOutgoing().artifact(
+ target.getBinaryTestResultsDirectory(),
+ artifact -> artifact.setType(ArtifactTypeDefinition.DIRECTORY_TYPE)
+ );
+ });
+ });
+ });
+ }
+
+ private static NamedDomainObjectProvider<ConsumableConfiguration> addTestResultsVariant(Project project, TestSuite suite) {
+ String variantName = String.format("testResultsElementsFor%s", StringUtils.capitalize(suite.getName()));
+
+ return project.getConfigurations().consumable(variantName, conf -> {
+ conf.setDescription("Binary results obtained from running all targets in the '" + suite.getName() + "' Test Suite.");
+
+ ObjectFactory objects = project.getObjects();
+ conf.attributes(attributes -> {
+ attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
+ attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.TEST_RESULTS));
+
+ // TODO: Allow targets to define attributes uniquely identifying themselves.
+ // Then, create a test results variant for each target instead of each suite.
+ attributes.attribute(TestSuiteName.TEST_SUITE_NAME_ATTRIBUTE, objects.named(TestSuiteName.class, suite.getName()));
+ });
+ });
}
}
diff --git a/subprojects/core-api/src/main/java/org/gradle/api/attributes/TestSuiteTargetName.java b/subprojects/core-api/src/main/java/org/gradle/api/attributes/TestSuiteTargetName.java
deleted file mode 100644
index fe60446..0000000
--- a/subprojects/core-api/src/main/java/org/gradle/api/attributes/TestSuiteTargetName.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.gradle.api.attributes;
-
-import org.gradle.api.Incubating;
-import org.gradle.api.Named;
-
-/**
- * Attribute to define the test suite target's name.
- * <p>
- * This attribute is usually found on variants that have the {@link Category} attribute valued at {@link Category#VERIFICATION verification}.
- *
- * @since 7.4
- */
-@Incubating
-public interface TestSuiteTargetName extends Named {
- Attribute<TestSuiteTargetName> TEST_SUITE_TARGET_NAME_ATTRIBUTE = Attribute.of("org.gradle.testsuite.target.name", TestSuiteTargetName.class);
-}
diff --git a/subprojects/core-api/src/main/java/org/gradle/api/attributes/TestSuiteType.java b/subprojects/core-api/src/main/java/org/gradle/api/attributes/TestSuiteType.java
deleted file mode 100644
index 8e3918c..0000000
--- a/subprojects/core-api/src/main/java/org/gradle/api/attributes/TestSuiteType.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.gradle.api.attributes;
-
-import org.gradle.api.Incubating;
-import org.gradle.api.Named;
-
-/**
- * Attribute to qualify the type of testing a test suite will perform.
- * <p>
- * This attribute is usually found on variants that have the {@link Category} attribute valued at {@link Category#VERIFICATION verification}.
- * <p>
- * The constant values present here are not exhaustive. Any value is allowed, so long as that value
- * is only used to categorize a single test suite within each project.
- *
- * @since 7.4
- */
-@Incubating
-public interface TestSuiteType extends Named {
- Attribute<TestSuiteType> TEST_SUITE_TYPE_ATTRIBUTE = Attribute.of("org.gradle.testsuite.type", TestSuiteType.class);
-
- /**
- * Unit tests, the default type of test suite
- */
- String UNIT_TEST = "unit-test";
-
- String INTEGRATION_TEST = "integration-test";
-
- /**
- * Functional tests, will be added automatically when initializing a new plugin project
- */
- String FUNCTIONAL_TEST = "functional-test";
-
- String PERFORMANCE_TEST = "performance-test";
-}
diff --git a/subprojects/core/src/main/java/org/gradle/api/internal/attributes/IncubatingAttributesChecker.java b/subprojects/core/src/main/java/org/gradle/api/internal/attributes/IncubatingAttributesChecker.java
index 50a2456..d0a028a 100644
--- a/subprojects/core/src/main/java/org/gradle/api/internal/attributes/IncubatingAttributesChecker.java
+++ b/subprojects/core/src/main/java/org/gradle/api/internal/attributes/IncubatingAttributesChecker.java
@@ -37,7 +37,7 @@
* An attribute is incubating iff it is a type annotated with {@link org.gradle.api.Incubating}, or if the value is equal to the value of a constant defined
* in the corresponding attribute interface which is annotated with {@link org.gradle.api.Incubating}.
*
- * For example, any attribute named {@link org.gradle.api.attributes.TestSuiteType} is currently incubating, as is a {@link Category#CATEGORY_ATTRIBUTE} with a value
+ * For example, any attribute named {@link org.gradle.api.attributes.TestSuiteName} is currently incubating, as is a {@link Category#CATEGORY_ATTRIBUTE} with a value
* equal to {@link Category#VERIFICATION}.
*
* @since 7.5
diff --git a/subprojects/core/src/test/groovy/org/gradle/api/internal/attributes/IncubatingAttributesCheckerTest.groovy b/subprojects/core/src/test/groovy/org/gradle/api/internal/attributes/IncubatingAttributesCheckerTest.groovy
index 6ce4dc4..4bd8619 100644
--- a/subprojects/core/src/test/groovy/org/gradle/api/internal/attributes/IncubatingAttributesCheckerTest.groovy
+++ b/subprojects/core/src/test/groovy/org/gradle/api/internal/attributes/IncubatingAttributesCheckerTest.groovy
@@ -17,7 +17,7 @@
package org.gradle.api.internal.attributes
import org.gradle.api.attributes.Category
-import org.gradle.api.attributes.TestSuiteType
+import org.gradle.api.attributes.TestSuiteName
import org.gradle.api.attributes.Usage
import org.gradle.util.AttributeTestUtil
import org.gradle.util.TestUtil
@@ -34,7 +34,7 @@
def "attribute with @Incubating annotation on class is reported"() {
expect:
- !IncubatingAttributesChecker.isIncubating(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE)
+ !IncubatingAttributesChecker.isIncubating(TestSuiteName.TEST_SUITE_NAME_ATTRIBUTE)
}
def "attribute without @Incubating annotation on class, with @Incubating on value is reported"() {
@@ -64,7 +64,7 @@
def "container with @Incubating attribute is reported"() {
def container = new DefaultMutableAttributeContainer(attributesFactory)
- container.attribute(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE, TestUtil.objectFactory().named(TestSuiteType, TestSuiteType.INTEGRATION_TEST))
+ container.attribute(TestSuiteName.TEST_SUITE_NAME_ATTRIBUTE, TestUtil.objectFactory().named(TestSuiteName, "foo"))
expect:
IncubatingAttributesChecker.isAnyIncubating(container)
diff --git a/subprojects/diagnostics/src/integTest/groovy/org/gradle/api/tasks/diagnostics/DependencyInsightReportVariantDetailsIntegrationTest.groovy b/subprojects/diagnostics/src/integTest/groovy/org/gradle/api/tasks/diagnostics/DependencyInsightReportVariantDetailsIntegrationTest.groovy
index f79a0e6..c278168 100644
--- a/subprojects/diagnostics/src/integTest/groovy/org/gradle/api/tasks/diagnostics/DependencyInsightReportVariantDetailsIntegrationTest.groovy
+++ b/subprojects/diagnostics/src/integTest/groovy/org/gradle/api/tasks/diagnostics/DependencyInsightReportVariantDetailsIntegrationTest.groovy
@@ -201,8 +201,6 @@
${variantOf('testResultsElementsForTest', [
'org.gradle.testsuite.name': of('test', ''),
- 'org.gradle.testsuite.target.name': of('test', ''),
- 'org.gradle.testsuite.type': of('unit-test', ''),
'org.gradle.verificationtype': of('test-results', ''),
'org.gradle.category': of('verification', 'library'),
'org.gradle.dependency.bundling': of('', 'external'),
@@ -314,8 +312,6 @@
${variantOf('testResultsElementsForTest', [
'org.gradle.testsuite.name': of('test', ''),
- 'org.gradle.testsuite.target.name': of('test', ''),
- 'org.gradle.testsuite.type': of('unit-test', ''),
'org.gradle.verificationtype': of('test-results', ''),
'org.gradle.category': of('verification', 'library'),
'org.gradle.dependency.bundling': of('', 'external'),
diff --git a/subprojects/diagnostics/src/integTest/groovy/org/gradle/api/tasks/diagnostics/OutgoingVariantsReportTaskIntegrationTest.groovy b/subprojects/diagnostics/src/integTest/groovy/org/gradle/api/tasks/diagnostics/OutgoingVariantsReportTaskIntegrationTest.groovy
index 3783037..297c68e 100644
--- a/subprojects/diagnostics/src/integTest/groovy/org/gradle/api/tasks/diagnostics/OutgoingVariantsReportTaskIntegrationTest.groovy
+++ b/subprojects/diagnostics/src/integTest/groovy/org/gradle/api/tasks/diagnostics/OutgoingVariantsReportTaskIntegrationTest.groovy
@@ -344,16 +344,14 @@
--------------------------------------------------
Variant testResultsElementsForTest (i)
--------------------------------------------------
-Directory containing binary results of running tests for the test Test Suite's test target.
+Binary results obtained from running all targets in the 'test' Test Suite.
Capabilities
- org:myLib:1.0 (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test
- - org.gradle.testsuite.target.name = test
- - org.gradle.testsuite.type = unit-test
- - org.gradle.verificationtype = test-results
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test
+ - org.gradle.verificationtype = test-results
Artifacts
- $resultsBinPath (artifactType = directory)
"""
@@ -532,16 +530,14 @@
--------------------------------------------------
Variant testResultsElementsForTest (i)
--------------------------------------------------
-Directory containing binary results of running tests for the test Test Suite's test target.
+Binary results obtained from running all targets in the 'test' Test Suite.
Capabilities
- org:myLib:1.0 (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test
- - org.gradle.testsuite.target.name = test
- - org.gradle.testsuite.type = unit-test
- - org.gradle.verificationtype = test-results
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test
+ - org.gradle.verificationtype = test-results
Artifacts
- $resultsBinPath (artifactType = directory)
""")
@@ -719,16 +715,14 @@
--------------------------------------------------
Variant testResultsElementsForTest (i)
--------------------------------------------------
-Directory containing binary results of running tests for the test Test Suite's test target.
+Binary results obtained from running all targets in the 'test' Test Suite.
Capabilities
- org:myLib:1.0 (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test
- - org.gradle.testsuite.target.name = test
- - org.gradle.testsuite.type = unit-test
- - org.gradle.verificationtype = test-results
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test
+ - org.gradle.verificationtype = test-results
Artifacts
- $resultsBinPath (artifactType = directory)
""")
@@ -939,16 +933,14 @@
--------------------------------------------------
Variant testResultsElementsForTest (i)
--------------------------------------------------
-Directory containing binary results of running tests for the test Test Suite's test target.
+Binary results obtained from running all targets in the 'test' Test Suite.
Capabilities
- org:myLib:1.0 (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test
- - org.gradle.testsuite.target.name = test
- - org.gradle.testsuite.type = unit-test
- - org.gradle.verificationtype = test-results
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test
+ - org.gradle.verificationtype = test-results
Artifacts
- $resultsBinPath (artifactType = directory)
""")
@@ -1091,16 +1083,14 @@
--------------------------------------------------
Variant testResultsElementsForTest (i)
--------------------------------------------------
-Directory containing binary results of running tests for the test Test Suite's test target.
+Binary results obtained from running all targets in the 'test' Test Suite.
Capabilities
- org:myLib:1.0 (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test
- - org.gradle.testsuite.target.name = test
- - org.gradle.testsuite.type = unit-test
- - org.gradle.verificationtype = test-results
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test
+ - org.gradle.verificationtype = test-results
Artifacts
- $resultsBinPath (artifactType = directory)
""")
@@ -1362,16 +1352,14 @@
--------------------------------------------------
Variant testResultsElementsForTest (i)
--------------------------------------------------
-Directory containing binary results of running tests for the test Test Suite's test target.
+Binary results obtained from running all targets in the 'test' Test Suite.
Capabilities
- org:myLib:1.0 (default capability)
Attributes
- - org.gradle.category = verification
- - org.gradle.testsuite.name = test
- - org.gradle.testsuite.target.name = test
- - org.gradle.testsuite.type = unit-test
- - org.gradle.verificationtype = test-results
+ - org.gradle.category = verification
+ - org.gradle.testsuite.name = test
+ - org.gradle.verificationtype = test-results
Artifacts
- $resultsBinPath (artifactType = directory)
""")