From cb9382d9866d6259b6c7280fc6a71e4f4d5583e9 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 29 Oct 2023 10:16:32 +0100 Subject: [PATCH] Polishing --- .../test/context/aot/AotIntegrationTests.java | 39 ++++++++++++------- ...ParameterizedDependencyInjectionTests.java | 4 +- .../rules/ParameterizedSpringRuleTests.java | 2 +- .../junit4/spr4868/Jsr250LifecycleTests.java | 4 +- 4 files changed, 29 insertions(+), 20 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 45fe14b925..a018c90271 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 @@ -27,7 +27,6 @@ import java.util.stream.Stream; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.platform.engine.TestSource; -import org.junit.platform.engine.discovery.ClassNameFilter; import org.junit.platform.engine.support.descriptor.ClassSource; import org.junit.platform.engine.support.descriptor.MethodSource; import org.junit.platform.launcher.LauncherDiscoveryRequest; @@ -55,6 +54,7 @@ import org.springframework.test.context.aot.samples.basic.DisabledInAotRuntimeCl import org.springframework.test.context.aot.samples.basic.DisabledInAotRuntimeMethodLevelTests; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.platform.engine.discovery.ClassNameFilter.includeClassNamePatterns; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; import static org.junit.platform.launcher.TagFilter.excludeTags; @@ -67,16 +67,16 @@ import static org.junit.platform.launcher.TagFilter.excludeTags; @CompileWithForkedClassLoader class AotIntegrationTests extends AbstractAotTests { - private static final String CLASSPATH_ROOT = "AotSmokeTests.classpath_root"; + private static final String CLASSPATH_ROOT = "AotIntegrationTests.classpath_root"; // We have to determine the classpath root and store it in a system property - // since @CompileWithTargetClassAccess uses a custom ClassLoader that does + // since @CompileWithForkedClassLoader uses a custom ClassLoader that does // not support CodeSource. // // The system property will only be set when this class is loaded by the // original ClassLoader used to launch the JUnit Platform. The attempt to // access the CodeSource will fail when the tests are executed in the - // nested JUnit Platform launched by the CompileWithTargetClassAccessExtension. + // nested JUnit Platform launched by the CompileWithForkedClassLoaderExtension. static { try { Path classpathRoot = Paths.get(AotIntegrationTests.class.getProtectionDomain().getCodeSource().getLocation().toURI()); @@ -122,16 +122,10 @@ class AotIntegrationTests extends AbstractAotTests { /* 1 */ DisabledInAotRuntimeMethodLevelTests.class))); } - @Disabled("Uncomment to run all Spring integration tests in `spring-test`") + @Disabled("Comment out to run all integration tests in spring-test in AOT mode") @Test void endToEndTestsForEntireSpringTestModule() { // AOT BUILD-TIME: CLASSPATH SCANNING - // - // 1) You can limit execution to a particular set of test classes. - // List> testClasses = List.of(org.springframework.test.web.servlet.samples.spr.EncodedUriTests.class, - // org.springframework.test.web.servlet.samples.spr.HttpOptionsTests.class); - // - // 2) Or you can use the TestClassScanner to find test classes. List> testClasses = createTestClassScanner() // Scan all base packages in spring-test. .scan("org.springframework.mock", "org.springframework.test") @@ -141,14 +135,29 @@ class AotIntegrationTests extends AbstractAotTests { // We only include test classes named *Tests so that we don't pick up // internal TestCase classes that aren't really tests. .filter(clazz -> clazz.getSimpleName().endsWith("Tests")) - // We don't have a way to abort a TestNG test mid-flight, and @EJB is not supported in AOT. + // We don't yet have a way to abort a TestNG test mid-flight, and @EJB is not supported in AOT. .filter(clazz -> !clazz.getPackageName().contains("testng.transaction.ejb")) .toList(); + // Optionally set failOnError flag to true to halt processing at the first failure. + runEndToEndTests(testClasses, false); + } + + @Disabled("Comment out to run selected integration tests in AOT mode") + @Test + void endToEndTestsForSelectedTestClasses() { + List> testClasses = List.of( + org.springframework.test.context.junit4.SpringJUnit4ClassRunnerAppCtxTests.class, + org.springframework.test.context.junit4.ParameterizedDependencyInjectionTests.class + ); + + runEndToEndTests(testClasses, true); + } + + private void runEndToEndTests(List> testClasses, boolean failOnError) { // AOT BUILD-TIME: PROCESSING InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles(); - // Optionally set failOnError flag to true to halt processing at the first failure. - TestContextAotGenerator generator = new TestContextAotGenerator(generatedFiles, new RuntimeHints(), false); + TestContextAotGenerator generator = new TestContextAotGenerator(generatedFiles, new RuntimeHints(), failOnError); generator.processAheadOfTime(testClasses.stream()); // AOT BUILD-TIME: COMPILATION @@ -168,7 +177,7 @@ class AotIntegrationTests extends AbstractAotTests { System.setProperty(AotDetector.AOT_ENABLED, "true"); LauncherDiscoveryRequestBuilder builder = LauncherDiscoveryRequestBuilder.request() - .filters(ClassNameFilter.includeClassNamePatterns(".*Tests?$")) + .filters(includeClassNamePatterns(".*Tests?$")) .filters(excludeTags("failing-test-case")); testClasses.forEach(testClass -> builder.selectors(selectClass(testClass))); LauncherDiscoveryRequest request = builder.build(); diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/ParameterizedDependencyInjectionTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/ParameterizedDependencyInjectionTests.java index 20b2307ab8..0ef57abb30 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/ParameterizedDependencyInjectionTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/ParameterizedDependencyInjectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(Parameterized.class) @ContextConfiguration -@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class }) +@TestExecutionListeners(DependencyInjectionTestExecutionListener.class) public class ParameterizedDependencyInjectionTests { private static final AtomicInteger invocationCount = new AtomicInteger(); diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ParameterizedSpringRuleTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ParameterizedSpringRuleTests.java index 05fd6a6b96..6492fed328 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ParameterizedSpringRuleTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/rules/ParameterizedSpringRuleTests.java @@ -46,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @see org.springframework.test.context.junit4.ParameterizedDependencyInjectionTests */ @RunWith(Parameterized.class) -@ContextConfiguration("/org/springframework/test/context/junit4/ParameterizedDependencyInjectionTests-context.xml") +@ContextConfiguration("../ParameterizedDependencyInjectionTests-context.xml") public class ParameterizedSpringRuleTests { private static final AtomicInteger invocationCount = new AtomicInteger(); diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/Jsr250LifecycleTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/Jsr250LifecycleTests.java index e7889b9239..634859211e 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/Jsr250LifecycleTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr4868/Jsr250LifecycleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 3.2 */ @RunWith(SpringJUnit4ClassRunner.class) -@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class }) +@TestExecutionListeners(DependencyInjectionTestExecutionListener.class) @ContextConfiguration public class Jsr250LifecycleTests {