mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 14:01:42 +00:00
Resolve all default context configuration within test class hierarchies
Prior to this commit, if a superclass or enclosing test class (such as one annotated with @SpringBootTest or simply @ExtendWith(SpringExtension.class)) was not annotated with @ContextConfiguration (or @Import with @SpringBootTest), the ApplicationContext loaded for a subclass or @Nested test class would not use any default context configuration for the superclass or enclosing test class. Effectively, a default XML configuration file or static nested @Configuration class for the superclass or enclosing test class was not discovered by the AbstractTestContextBootstrapper when attempting to build the MergedContextConfiguration (application context cache key). To address that, this commit introduces a new resolveDefaultContextConfigurationAttributes() method in ContextLoaderUtils which is responsible for creating instances of ContextConfigurationAttributes for all superclasses and enclosing classes. This effectively enables AbstractTestContextBootstrapper to delegate to the resolved SmartContextLoader to properly detect a default XML configuration file or static nested @Configuration class even if such classes are not annotated with @ContextConfiguration. Closes gh-31456
This commit is contained in:
+1
-1
@@ -46,7 +46,7 @@ class ImplicitDefaultConfigClassesBaseTests {
|
||||
|
||||
|
||||
@Test
|
||||
void greeting1AndPuzzle1() {
|
||||
final void greeting1AndPuzzle1() {
|
||||
// This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration.
|
||||
assertThat(AnnotatedElementUtils.hasAnnotation(getClass(), ContextConfiguration.class)).isFalse();
|
||||
|
||||
|
||||
+1
-10
@@ -41,14 +41,6 @@ class ImplicitDefaultConfigClassesInheritedTests extends ImplicitDefaultConfigCl
|
||||
String greeting2;
|
||||
|
||||
|
||||
// To be removed in favor of base class method in 7.1
|
||||
@Test
|
||||
@Override
|
||||
void greeting1AndPuzzle1() {
|
||||
assertThat(greeting1).isEqualTo("TEST 2");
|
||||
assertThat(puzzle1).isEqualTo(222);
|
||||
}
|
||||
|
||||
@Test
|
||||
void greeting2() {
|
||||
// This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration.
|
||||
@@ -59,8 +51,7 @@ class ImplicitDefaultConfigClassesInheritedTests extends ImplicitDefaultConfigCl
|
||||
|
||||
@Test
|
||||
void greetings(@Autowired List<String> greetings) {
|
||||
assertThat(greetings).containsExactly("TEST 2");
|
||||
// for 7.1: assertThat(greetings).containsExactly("TEST 1", "TEST 2");
|
||||
assertThat(greetings).containsExactly("TEST 1", "TEST 2");
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.test.context.junit.jupiter.nested;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@@ -53,7 +54,6 @@ class DefaultContextConfigurationDetectionWithNestedTests {
|
||||
}
|
||||
|
||||
|
||||
/** for 7.1:
|
||||
@Nested
|
||||
class NestedTests {
|
||||
|
||||
@@ -63,7 +63,6 @@ class DefaultContextConfigurationDetectionWithNestedTests {
|
||||
assertThat(localGreeting).isEqualTo("TEST");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Configuration
|
||||
|
||||
Reference in New Issue
Block a user