From d4a5565340ab365ac52e8524b7da1f880eec9d14 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 8 Oct 2022 16:30:02 +0200 Subject: [PATCH] Enable default TestExecutionListeners in JUnit 4 and TestNG base test classes Prior to this commit, the abstract base test classes for JUnit 4 and TestNG registered explicit sets of TestExecutionListeners. This configuration was useful in the early years of the Spring TestContext Framework. However, since the introduction of support for automatic registration of "default" listeners in Spring Framework 4.1, these predefined sets of TestExecutionListeners have become a hindrance to using Spring's testing support with default listeners from Spring portfolio projects (such as Spring Boot and Spring Security) as well as third-party or project-specific default listeners. To address this issue, the four abstract base test classes for JUnit 4 and TestNG no longer declare listeners via @TestExecutionListeners and instead now rely on registration of default listeners. Closes gh-29149 --- .../AbstractJUnit4SpringContextTests.java | 35 +---------------- ...TransactionalJUnit4SpringContextTests.java | 30 --------------- .../AbstractTestNGSpringContextTests.java | 38 ++----------------- ...TransactionalTestNGSpringContextTests.java | 31 --------------- 4 files changed, 4 insertions(+), 130 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.java b/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.java index 9656257819..9c39288080 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.java @@ -27,12 +27,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestContext; import org.springframework.test.context.TestContextManager; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.event.ApplicationEventsTestExecutionListener; -import org.springframework.test.context.event.EventPublishingTestExecutionListener; -import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; -import org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener; -import org.springframework.test.context.support.DirtiesContextTestExecutionListener; -import org.springframework.test.context.web.ServletTestExecutionListener; /** * Abstract base test class which integrates the Spring TestContext @@ -43,25 +37,7 @@ import org.springframework.test.context.web.ServletTestExecutionListener; * {@link ContextConfiguration @ContextConfiguration} annotation to * configure the {@linkplain ApplicationContext application context} {@linkplain * ContextConfiguration#locations() resource locations} or {@linkplain - * ContextConfiguration#classes() component classes}. If your test does not - * need to load an application context, you may choose to omit the - * {@link ContextConfiguration @ContextConfiguration} declaration and to configure - * the appropriate {@link org.springframework.test.context.TestExecutionListener - * TestExecutionListeners} manually. - * - *

This class explicitly registers the following {@code TestExecutionListener} - * implementations. If you want to switch to using the default set of - * listeners, see the class-level Javadoc for - * {@link TestExecutionListeners @TestExecutionListeners} for details. - * - *

+ * ContextConfiguration#classes() component classes}. * *

This class serves only as a convenience for extension. *