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 93efd431cc2e..b79117a0bcc9 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 @@ -26,8 +26,10 @@ 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; import org.junit.platform.launcher.TestIdentifier; import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; @@ -176,18 +178,7 @@ private static void runTestsInAotMode(long expectedNumTests, List> test summary.printTo(new PrintWriter(System.err)); } if (summary.getTotalFailureCount() > 0) { - System.err.println("Failing Test Classes:"); - summary.getFailures().stream() - .map(Failure::getTestIdentifier) - .map(TestIdentifier::getSource) - .flatMap(Optional::stream) - .filter(ClassSource.class::isInstance) - .map(ClassSource.class::cast) - .map(AotIntegrationTests::getJavaClass) - .flatMap(Optional::stream) - .map(Class::getName) - .forEach(System.err::println); - System.err.println(); + printFailingTestClasses(summary); List exceptions = summary.getFailures().stream().map(Failure::getException).toList(); throw new MultipleFailuresError("Test execution failures", exceptions); } @@ -200,6 +191,30 @@ private static void runTestsInAotMode(long expectedNumTests, List> test } } + private static void printFailingTestClasses(TestExecutionSummary summary) { + System.err.println("Failing Test Classes:"); + summary.getFailures().stream() + .map(Failure::getTestIdentifier) + .map(TestIdentifier::getSource) + .flatMap(Optional::stream) + .map(TestSource.class::cast) + .map(source -> { + if (source instanceof ClassSource classSource) { + return getJavaClass(classSource); + } + else if (source instanceof MethodSource methodSource) { + return getJavaClass(methodSource); + } + return Optional.> empty(); + }) + .flatMap(Optional::stream) + .map(Class::getName) + .distinct() + .sorted() + .forEach(System.err::println); + System.err.println(); + } + private static Optional> getJavaClass(ClassSource classSource) { try { return Optional.of(classSource.getJavaClass()); @@ -210,6 +225,16 @@ private static Optional> getJavaClass(ClassSource classSource) { } } + private static Optional> getJavaClass(MethodSource methodSource) { + try { + return Optional.of(methodSource.getJavaClass()); + } + catch (Exception ex) { + // ignore exception + return Optional.empty(); + } + } + private static TestClassScanner createTestClassScanner() { String classpathRoot = System.getProperty(CLASSPATH_ROOT); assertThat(classpathRoot).as(CLASSPATH_ROOT).isNotNull();