Skip to content

Commit

Permalink
Print test summary for AotIntegrationTests.endToEndTestsForEntireSpri…
Browse files Browse the repository at this point in the history
…ngTestModule()

Current results for the spring-test module:

Test run finished after 6785 ms
[       403 containers found      ]
[         6 containers skipped    ]
[       397 containers started    ]
[         0 containers aborted    ]
[       381 containers successful ]
[        16 containers failed     ]
[       757 tests found           ]
[        41 tests skipped         ]
[       703 tests started         ]
[         9 tests aborted         ]
[       599 tests successful      ]
[        95 tests failed          ]

Failing Test Classes:
org.springframework.test.context.testng.transaction.ejb.RollbackForRequiresNewEjbTxDaoTestNGTests
org.springframework.test.context.testng.transaction.ejb.CommitForRequiredEjbTxDaoTestNGTests
org.springframework.test.context.testng.transaction.ejb.RollbackForRequiredEjbTxDaoTestNGTests
org.springframework.test.context.testng.transaction.ejb.CommitForRequiresNewEjbTxDaoTestNGTests
org.springframework.test.context.env.ExplicitPropertiesFileTestPropertySourceTests$ClasspathTests$PlaceholderAndClasspathPrefixTests
org.springframework.test.context.env.ExplicitPropertiesFileTestPropertySourceTests$ClasspathTests$PlaceholderTests
org.springframework.test.context.env.ExplicitPropertiesFileTestPropertySourceTests$FileSystemTests$CustomPlaceholderTests
org.springframework.test.context.env.ExplicitPropertiesFileTestPropertySourceTests$FileSystemTests$PlaceholdersFollowedByRelativePathsTests
org.springframework.test.context.env.ExplicitPropertiesFileTestPropertySourceTests$FileSystemTests$UserDirAndCustomPlaceholdersTests
org.springframework.test.web.servlet.samples.client.context.WebAppResourceTests
org.springframework.test.web.servlet.samples.client.context.XmlConfigTests
org.springframework.test.web.servlet.samples.context.WebAppResourceTests
org.springframework.test.web.servlet.samples.context.XmlConfigTests
org.springframework.test.context.junit4.ParameterizedDependencyInjectionTests
org.springframework.test.context.junit4.nested.NestedTestsWithSpringRulesTests$NestedTestCase
org.springframework.test.context.junit4.spr9799.Spr9799XmlConfigTests

See gh-29122
  • Loading branch information
sbrannen committed Oct 16, 2023
1 parent 3ad79e9 commit 41098d5
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@

package org.springframework.test.context.aot;

import java.io.PrintWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
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.engine.discovery.ClassNameFilter;
import org.junit.platform.engine.support.descriptor.ClassSource;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.TestIdentifier;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
Expand Down Expand Up @@ -123,7 +127,8 @@ void endToEndTestsForEntireSpringTestModule() {
// AOT BUILD-TIME: CLASSPATH SCANNING
//
// 1) You can limit execution to a particular set of test classes.
// List<Class<?>> testClasses = List.of(DirtiesContextTransactionalTestNGSpringContextTests.class);
// List<Class<?>> 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<Class<?>> testClasses = createTestClassScanner()
Expand All @@ -138,7 +143,7 @@ void endToEndTestsForEntireSpringTestModule() {

// AOT BUILD-TIME: PROCESSING
InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles();
// Set failOnError flag to false to allow processing to continue.
// Optionally set failOnError flag to true to halt processing at the first failure.
TestContextAotGenerator generator = new TestContextAotGenerator(generatedFiles, new RuntimeHints(), false);
generator.processAheadOfTime(testClasses.stream());

Expand Down Expand Up @@ -166,7 +171,22 @@ private static void runTestsInAotMode(long expectedNumTests, List<Class<?>> test
SummaryGeneratingListener listener = new SummaryGeneratingListener();
LauncherFactory.create().execute(request, listener);
TestExecutionSummary summary = listener.getSummary();
if (expectedNumTests < 0) {
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();
List<Throwable> exceptions = summary.getFailures().stream().map(Failure::getException).toList();
throw new MultipleFailuresError("Test execution failures", exceptions);
}
Expand All @@ -179,6 +199,16 @@ private static void runTestsInAotMode(long expectedNumTests, List<Class<?>> test
}
}

private static Optional<Class<?>> getJavaClass(ClassSource classSource) {
try {
return Optional.of(classSource.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();
Expand Down

0 comments on commit 41098d5

Please sign in to comment.