diff --git a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc index 97f1d6145c9..bbb97297e97 100644 --- a/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc +++ b/framework-docs/modules/ROOT/pages/testing/testcontext-framework/tel-config.adoc @@ -16,7 +16,8 @@ by default, exactly in the following order: Micrometer's `ObservationRegistry`. * `DirtiesContextTestExecutionListener`: Handles the `@DirtiesContext` annotation for "`after`" modes. -* `CommonCacheTestExecutionListener`: Clears application context cache if necessary. +* `CommonCacheTestExecutionListener`: Clears resource caches in the test's + `ApplicationContext` if necessary. * `TransactionalTestExecutionListener`: Provides transactional test execution with default rollback semantics. * `SqlScriptsTestExecutionListener`: Runs SQL scripts configured by using the `@Sql` diff --git a/spring-test/src/main/resources/META-INF/spring.factories b/spring-test/src/main/resources/META-INF/spring.factories index 9bfc8ed723b..deb80310e2f 100644 --- a/spring-test/src/main/resources/META-INF/spring.factories +++ b/spring-test/src/main/resources/META-INF/spring.factories @@ -6,9 +6,9 @@ org.springframework.test.context.TestExecutionListener = \ org.springframework.test.context.event.ApplicationEventsTestExecutionListener,\ org.springframework.test.context.bean.override.mockito.MockitoTestExecutionListener,\ org.springframework.test.context.support.DependencyInjectionTestExecutionListener,\ - org.springframework.test.context.support.CommonCacheTestExecutionListener,\ org.springframework.test.context.observation.MicrometerObservationRegistryTestExecutionListener,\ org.springframework.test.context.support.DirtiesContextTestExecutionListener,\ + org.springframework.test.context.support.CommonCacheTestExecutionListener,\ org.springframework.test.context.transaction.TransactionalTestExecutionListener,\ org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener,\ org.springframework.test.context.event.EventPublishingTestExecutionListener,\ diff --git a/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionCommonCacheTests.java b/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionCommonCacheTests.java index 66912a53fd7..e0533bed267 100644 --- a/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionCommonCacheTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/cache/SpringExtensionCommonCacheTests.java @@ -30,20 +30,19 @@ import org.springframework.context.annotation.Lazy; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.core.io.ResourceLoader; import org.springframework.core.type.classreading.MetadataReader; -import org.springframework.test.context.cache.SpringExtensionCommonCacheTests.TestConfiguration; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * Tests that verify that common caches are cleared at the end of a test - * class. Regular callback cannot be used to validate this as they run + * class. Regular callbacks cannot be used to validate this as they run * before the listener, so we need two test classes that are ordered to * validate the result. * * @author Stephane Nicoll */ -@SpringJUnitConfig(classes = TestConfiguration.class) +@SpringJUnitConfig @TestClassOrder(ClassOrderer.OrderAnnotation.class) class SpringExtensionCommonCacheTests { @@ -56,7 +55,7 @@ class SpringExtensionCommonCacheTests { @Test void lazyInitBeans() { - applicationContext.getBean(String.class); + assertThat(applicationContext.getBean(String.class)).isEqualTo("Dummy"); assertThat(applicationContext.getResourceCache(MetadataReader.class)).isNotEmpty(); }