Skip to content

Commit 44500cf

Browse files
committed
Revise TestConventions to retain existing JUnit Platform options
This commit revises the implementation of TestConventions so that existing JUnit Platform options from a pre-configured `test` task are copied instead of overridden. Closes gh-34827
1 parent e384389 commit 44500cf

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

buildSrc/src/main/java/org/springframework/build/TestConventions.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
2121
import org.gradle.api.Project;
2222
import org.gradle.api.plugins.JavaBasePlugin;
2323
import org.gradle.api.tasks.testing.Test;
24+
import org.gradle.api.tasks.testing.TestFrameworkOptions;
25+
import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions;
2426
import org.gradle.testretry.TestRetryPlugin;
2527
import org.gradle.testretry.TestRetryTaskExtension;
2628

@@ -34,6 +36,7 @@
3436
*
3537
* @author Brian Clozel
3638
* @author Andy Wilkinson
39+
* @author Sam Brannen
3740
*/
3841
class TestConventions {
3942

@@ -50,7 +53,12 @@ private void configureTestConventions(Project project) {
5053
}
5154

5255
private void configureTests(Project project, Test test) {
53-
test.useJUnitPlatform();
56+
TestFrameworkOptions existingOptions = test.getOptions();
57+
test.useJUnitPlatform(options -> {
58+
if (existingOptions instanceof JUnitPlatformOptions junitPlatformOptions) {
59+
options.copyFrom(junitPlatformOptions);
60+
}
61+
});
5462
test.include("**/*Tests.class", "**/*Test.class");
5563
test.setSystemProperties(Map.of(
5664
"java.awt.headless", "true",

spring-test/spring-test.gradle

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,10 @@ test {
105105
description = "Runs JUnit 4, JUnit Jupiter, and TestNG tests."
106106
useJUnitPlatform {
107107
includeEngines "junit-vintage", "junit-jupiter", "testng"
108-
excludeTags "failing-test-case"
109108
}
110-
// We use `include` instead of `filter.includeTestsMatching`, since
111-
// the latter results in some tests being executed/reported
112-
// multiple times.
113-
include(["**/*Tests.class", "**/*Test.class"])
109+
// `include` test filters and system properties are configured in
110+
// org.springframework.build.TestConventions in buildSrc.
114111
filter.excludeTestsMatching("*TestCase")
115-
systemProperty("testGroups", project.properties.get("testGroups"))
116-
// Java Util Logging for the JUnit Platform.
112+
// Optionally configure Java Util Logging for the JUnit Platform.
117113
// systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
118114
}

0 commit comments

Comments
 (0)