From ae864eb6427e2bb0a82a51d4ac8cb99ecb48cc64 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 9 Sep 2022 17:42:18 +0200 Subject: [PATCH] Introduce @Disabled end-to-end AOT tests for the spring-test module This commit introduces endToEndTestsForEntireSpringTestModule() in AotIntegrationTests to allow us to periodically check on our AOT support. Status quo: - several test classes cannot be processed for AOT due to exceptions thrown during processing - some generated classes fail to compile - some tests fail See gh-29122 --- .../test/context/aot/AotIntegrationTests.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java index 61fbfe0e9d8..292c142b996 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Stream; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.platform.launcher.LauncherDiscoveryRequest; import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; @@ -45,6 +46,7 @@ import org.springframework.test.context.aot.samples.basic.BasicSpringVintageTest import static org.assertj.core.api.Assertions.assertThat; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; +import static org.junit.platform.launcher.TagFilter.excludeTags; /** * End-to-end integration tests for AOT support in the TestContext framework. @@ -103,12 +105,39 @@ class AotIntegrationTests extends AbstractAotTests { )); } + @Disabled("Uncomment to run all Spring integration tests in `spring-test`") + @Test + void endToEndTestsForEntireSpringTestModule() { + // AOT BUILD-TIME: CLASSPATH SCANNING + List> testClasses = createTestClassScanner() + .scan() + // FYI: you can limit execution to a particular package as follows. + // .scan("org.springframework.test.context.junit.jupiter") + .toList(); + + // AOT BUILD-TIME: PROCESSING + InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles(); + TestContextAotGenerator generator = new TestContextAotGenerator(generatedFiles); + generator.processAheadOfTime(testClasses.stream()); + + // AOT BUILD-TIME: COMPILATION + TestCompiler.forSystem().withFiles(generatedFiles) + // .printFiles(System.out) + .compile(compiled -> + // AOT RUN-TIME: EXECUTION + runTestsInAotMode(testClasses.toArray(Class[]::new))); + } + + private static void runTestsInAotMode(Class... testClasses) { + runTestsInAotMode(-1, testClasses); + } private static void runTestsInAotMode(long expectedNumTests, Class... testClasses) { try { System.setProperty(AotDetector.AOT_ENABLED, "true"); - LauncherDiscoveryRequestBuilder builder = LauncherDiscoveryRequestBuilder.request(); + LauncherDiscoveryRequestBuilder builder = LauncherDiscoveryRequestBuilder.request() + .filters(excludeTags("failing-test-case")); Arrays.stream(testClasses).forEach(testClass -> builder.selectors(selectClass(testClass))); LauncherDiscoveryRequest request = builder.build(); SummaryGeneratingListener listener = new SummaryGeneratingListener(); @@ -118,7 +147,9 @@ class AotIntegrationTests extends AbstractAotTests { List exceptions = summary.getFailures().stream().map(Failure::getException).toList(); throw new MultipleFailuresError("Test execution failures", exceptions); } - assertThat(summary.getTestsSucceededCount()).isEqualTo(expectedNumTests); + if (expectedNumTests >= 0) { + assertThat(summary.getTestsSucceededCount()).isEqualTo(expectedNumTests); + } } finally { System.clearProperty(AotDetector.AOT_ENABLED);