Browse Source

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
pull/35405/head
Sam Brannen 8 months ago
parent
commit
44500cf868
  1. 12
      buildSrc/src/main/java/org/springframework/build/TestConventions.java
  2. 10
      spring-test/spring-test.gradle

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@ -21,6 +21,8 @@ import java.util.Map; @@ -21,6 +21,8 @@ import java.util.Map;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.tasks.testing.Test;
import org.gradle.api.tasks.testing.TestFrameworkOptions;
import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions;
import org.gradle.testretry.TestRetryPlugin;
import org.gradle.testretry.TestRetryTaskExtension;
@ -34,6 +36,7 @@ import org.gradle.testretry.TestRetryTaskExtension; @@ -34,6 +36,7 @@ import org.gradle.testretry.TestRetryTaskExtension;
*
* @author Brian Clozel
* @author Andy Wilkinson
* @author Sam Brannen
*/
class TestConventions {
@ -50,7 +53,12 @@ class TestConventions { @@ -50,7 +53,12 @@ class TestConventions {
}
private void configureTests(Project project, Test test) {
test.useJUnitPlatform();
TestFrameworkOptions existingOptions = test.getOptions();
test.useJUnitPlatform(options -> {
if (existingOptions instanceof JUnitPlatformOptions junitPlatformOptions) {
options.copyFrom(junitPlatformOptions);
}
});
test.include("**/*Tests.class", "**/*Test.class");
test.setSystemProperties(Map.of(
"java.awt.headless", "true",

10
spring-test/spring-test.gradle

@ -105,14 +105,10 @@ test { @@ -105,14 +105,10 @@ test {
description = "Runs JUnit 4, JUnit Jupiter, and TestNG tests."
useJUnitPlatform {
includeEngines "junit-vintage", "junit-jupiter", "testng"
excludeTags "failing-test-case"
}
// We use `include` instead of `filter.includeTestsMatching`, since
// the latter results in some tests being executed/reported
// multiple times.
include(["**/*Tests.class", "**/*Test.class"])
// `include` test filters and system properties are configured in
// org.springframework.build.TestConventions in buildSrc.
filter.excludeTestsMatching("*TestCase")
systemProperty("testGroups", project.properties.get("testGroups"))
// Java Util Logging for the JUnit Platform.
// Optionally configure Java Util Logging for the JUnit Platform.
// systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
}

Loading…
Cancel
Save