Switch the default @NestedTestConfiguration mode to INHERIT.

See gh-19930
This commit is contained in:
Sam Brannen
2020-10-12 18:33:20 +02:00
parent 8c47c7c797
commit fbb3c5cce7
12 changed files with 39 additions and 32 deletions

View File

@@ -46,6 +46,7 @@ import static org.springframework.test.context.NestedTestConfiguration.Enclosing
*/
@SpringJUnitConfig(Config1.class)
@ActiveProfiles("1")
@NestedTestConfiguration(OVERRIDE) // since INHERIT is now the global default
class ActiveProfilesNestedTests {
@Autowired

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -25,12 +25,14 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.NestedTestConfiguration;
import org.springframework.test.context.junit.SpringJUnitJupiterTestSuite;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.context.junit.jupiter.nested.ConstructorInjectionNestedTests.TopLevelConfig;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration.OVERRIDE;
/**
* Integration tests that verify support for {@code @Nested} test classes in conjunction
@@ -47,6 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @see org.springframework.test.context.junit4.nested.NestedTestsWithSpringRulesTests
*/
@SpringJUnitConfig(TopLevelConfig.class)
@NestedTestConfiguration(OVERRIDE) // since INHERIT is now the global default
class ConstructorInjectionNestedTests {
final String foo;

View File

@@ -44,6 +44,7 @@ import static org.springframework.test.context.NestedTestConfiguration.Enclosing
* @see org.springframework.test.context.junit4.nested.NestedTestsWithSpringRulesTests
*/
@SpringJUnitConfig(TopLevelConfig.class)
@NestedTestConfiguration(OVERRIDE) // since INHERIT is now the global default
class ContextConfigurationNestedTests {
private static final String FOO = "foo";

View File

@@ -45,6 +45,7 @@ import static org.springframework.test.context.NestedTestConfiguration.Enclosing
*/
@ExtendWith(SpringExtension.class)
@ContextHierarchy(@ContextConfiguration(classes = ParentConfig.class))
@NestedTestConfiguration(OVERRIDE) // since INHERIT is now the global default
class ContextHierarchyNestedTests {
private static final String FOO = "foo";

View File

@@ -67,12 +67,6 @@ class SqlScriptNestedTests {
}
@Nested
// NOTE: the following @SpringJUnitConfig declaration must NOT be removed.
// This was added before the TestContext framework looked up configuration
// on enclosing classes for @Nested test classes. As such, this serves as a
// regression test and cannot be changed.
@SpringJUnitConfig(PopulatedSchemaDatabaseConfig.class)
@Transactional
class NestedTests {
@Autowired

View File

@@ -43,6 +43,7 @@ import static org.springframework.test.context.TestConstructor.AutowireMode.ANNO
*/
@SpringJUnitConfig
@TestConstructor(autowireMode = ALL)
@NestedTestConfiguration(OVERRIDE) // since INHERIT is now the global default
class TestConstructorNestedTests {
TestConstructorNestedTests(String text) {

View File

@@ -46,6 +46,7 @@ import static org.springframework.test.context.NestedTestConfiguration.Enclosing
*/
@SpringJUnitConfig
@TestExecutionListeners(FooTestExecutionListener.class)
@NestedTestConfiguration(OVERRIDE) // since INHERIT is now the global default
class TestExecutionListenersNestedTests {
private static final String FOO = "foo";

View File

@@ -42,6 +42,7 @@ import static org.springframework.test.context.NestedTestConfiguration.Enclosing
*/
@SpringJUnitConfig(Config.class)
@TestPropertySource(properties = "p1 = v1")
@NestedTestConfiguration(OVERRIDE) // since INHERIT is now the global default
class TestPropertySourceNestedTests {
@Autowired
@@ -160,6 +161,12 @@ class TestPropertySourceNestedTests {
}
@Nested
// The following explicit INHERIT is necessary since this nested
// test class implements an interface whose enclosing class is
// annotated with @NestedTestConfiguration(OVERRIDE). In other
// words, the local declaration overrides the declaration
// "inherited" via the interface.
@NestedTestConfiguration(INHERIT)
class L5WithInheritedConfigAndTestInterfaceTests implements TestInterface {
@Autowired

View File

@@ -53,6 +53,7 @@ import static org.springframework.transaction.annotation.Propagation.NOT_SUPPORT
@SpringJUnitConfig
@Transactional
@Commit
@NestedTestConfiguration(OVERRIDE) // since INHERIT is now the global default
class TransactionalNestedTests {
@Test

View File

@@ -44,6 +44,7 @@ import static org.springframework.test.context.NestedTestConfiguration.Enclosing
* @see org.springframework.test.context.junit4.nested.NestedTestsWithSpringRulesTests
*/
@SpringJUnitWebConfig(Config.class)
@NestedTestConfiguration(OVERRIDE) // since INHERIT is now the global default
class WebAppConfigurationNestedTests {
@Test