Skip to content

Commit cced3cb

Browse files
committed
Register runtime hints for @TestExecutionListeners
Closes gh-29024
1 parent 34635d7 commit cced3cb

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

spring-test/src/main/java/org/springframework/test/context/aot/TestContextAotGenerator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass) {
199199
TestContextBootstrapper testContextBootstrapper =
200200
BootstrapUtils.resolveTestContextBootstrapper(testClass);
201201
registerDeclaredConstructors(testContextBootstrapper.getClass());
202+
testContextBootstrapper.getTestExecutionListeners().stream()
203+
.map(Object::getClass)
204+
.forEach(this::registerDeclaredConstructors);
202205
return testContextBootstrapper.buildMergedContextConfiguration();
203206
}
204207

spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ private static void assertRuntimeHints(RuntimeHints runtimeHints) {
141141

142142
// TestExecutionListener
143143
Stream.of(
144+
org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyTestExecutionListener.class,
144145
org.springframework.test.context.event.ApplicationEventsTestExecutionListener.class,
145146
org.springframework.test.context.event.EventPublishingTestExecutionListener.class,
146147
org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener.class,

spring-test/src/test/java/org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323
import org.springframework.beans.factory.annotation.Autowired;
2424
import org.springframework.beans.factory.annotation.Value;
2525
import org.springframework.context.ApplicationContext;
26+
import org.springframework.test.context.TestExecutionListeners;
2627
import org.springframework.test.context.TestPropertySource;
28+
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyExtension;
29+
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests.DummyTestExecutionListener;
2730
import org.springframework.test.context.aot.samples.common.MessageService;
2831
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
32+
import org.springframework.test.context.support.AbstractTestExecutionListener;
2933

3034
import static org.assertj.core.api.Assertions.assertThat;
35+
import static org.springframework.test.context.TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS;
3136

3237
/**
3338
* @author Sam Brannen
@@ -37,6 +42,7 @@
3742
// for repeated annotations.
3843
@ExtendWith(DummyExtension.class)
3944
@SpringJUnitConfig(BasicTestConfiguration.class)
45+
@TestExecutionListeners(listeners = DummyTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS)
4046
@TestPropertySource(properties = "test.engine = jupiter")
4147
public class BasicSpringJupiterTests {
4248

@@ -65,7 +71,11 @@ void test(@Autowired ApplicationContext context, @Autowired MessageService messa
6571

6672
}
6773

68-
}
74+
static class DummyExtension implements Extension {
75+
}
76+
77+
public static class DummyTestExecutionListener extends AbstractTestExecutionListener {
78+
}
6979

70-
class DummyExtension implements Extension {
7180
}
81+

0 commit comments

Comments
 (0)