Skip to content

Commit

Permalink
Introduce @disabled end-to-end AOT tests for the spring-test module
Browse files Browse the repository at this point in the history
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 spring-projectsgh-29122
  • Loading branch information
sbrannen committed Sep 9, 2022
1 parent 94ff519 commit ae864eb
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand All @@ -45,6 +46,7 @@

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.
Expand Down Expand Up @@ -103,12 +105,39 @@ void endToEndTests() {
));
}

@Disabled("Uncomment to run all Spring integration tests in `spring-test`")
@Test
void endToEndTestsForEntireSpringTestModule() {
// AOT BUILD-TIME: CLASSPATH SCANNING
List<Class<?>> 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();
Expand All @@ -118,7 +147,9 @@ private static void runTestsInAotMode(long expectedNumTests, Class<?>... testCla
List<Throwable> 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);
Expand Down

0 comments on commit ae864eb

Please sign in to comment.