diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java index ca1c856c78..38f18d952d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java @@ -199,6 +199,9 @@ public class TestContextAotGenerator { TestContextBootstrapper testContextBootstrapper = BootstrapUtils.resolveTestContextBootstrapper(testClass); registerDeclaredConstructors(testContextBootstrapper.getClass()); + testContextBootstrapper.getTestExecutionListeners().stream() + .map(Object::getClass) + .forEach(this::registerDeclaredConstructors); return testContextBootstrapper.buildMergedContextConfiguration(); } diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java index 9204976146..48072cac42 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java @@ -141,6 +141,7 @@ class TestContextAotGeneratorTests extends AbstractAotTests { // TestExecutionListener Stream.of( + org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyTestExecutionListener.class, org.springframework.test.context.event.ApplicationEventsTestExecutionListener.class, org.springframework.test.context.event.EventPublishingTestExecutionListener.class, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener.class, diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java index 786a70797f..9d27c1f89d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java @@ -23,11 +23,16 @@ import org.junit.jupiter.api.extension.Extension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; +import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyExtension; +import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyTestExecutionListener; import org.springframework.test.context.aot.samples.common.MessageService; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import org.springframework.test.context.support.AbstractTestExecutionListener; import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.context.TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS; /** * @author Sam Brannen @@ -37,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; // for repeated annotations. @ExtendWith(DummyExtension.class) @SpringJUnitConfig(BasicTestConfiguration.class) +@TestExecutionListeners(listeners = DummyTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS) @TestPropertySource(properties = "test.engine = jupiter") public class BasicSpringJupiterTests { @@ -65,7 +71,11 @@ public class BasicSpringJupiterTests { } + static class DummyExtension implements Extension { + } + + public static class DummyTestExecutionListener extends AbstractTestExecutionListener { + } + } -class DummyExtension implements Extension { -}