16
16
17
17
package org .springframework .test .context .aot ;
18
18
19
+ import java .io .PrintWriter ;
19
20
import java .nio .file .Path ;
20
21
import java .nio .file .Paths ;
21
22
import java .util .List ;
23
+ import java .util .Optional ;
22
24
import java .util .Set ;
23
25
import java .util .stream .Stream ;
24
26
25
27
import org .junit .jupiter .api .Disabled ;
26
28
import org .junit .jupiter .api .Test ;
27
29
import org .junit .platform .engine .discovery .ClassNameFilter ;
30
+ import org .junit .platform .engine .support .descriptor .ClassSource ;
28
31
import org .junit .platform .launcher .LauncherDiscoveryRequest ;
32
+ import org .junit .platform .launcher .TestIdentifier ;
29
33
import org .junit .platform .launcher .core .LauncherDiscoveryRequestBuilder ;
30
34
import org .junit .platform .launcher .core .LauncherFactory ;
31
35
import org .junit .platform .launcher .listeners .SummaryGeneratingListener ;
@@ -123,7 +127,8 @@ void endToEndTestsForEntireSpringTestModule() {
123
127
// AOT BUILD-TIME: CLASSPATH SCANNING
124
128
//
125
129
// 1) You can limit execution to a particular set of test classes.
126
- // List<Class<?>> testClasses = List.of(DirtiesContextTransactionalTestNGSpringContextTests.class);
130
+ // List<Class<?>> testClasses = List.of(org.springframework.test.web.servlet.samples.spr.EncodedUriTests.class,
131
+ // org.springframework.test.web.servlet.samples.spr.HttpOptionsTests.class);
127
132
//
128
133
// 2) Or you can use the TestClassScanner to find test classes.
129
134
List <Class <?>> testClasses = createTestClassScanner ()
@@ -138,7 +143,7 @@ void endToEndTestsForEntireSpringTestModule() {
138
143
139
144
// AOT BUILD-TIME: PROCESSING
140
145
InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles ();
141
- // Set failOnError flag to false to allow processing to continue .
146
+ // Optionally set failOnError flag to true to halt processing at the first failure .
142
147
TestContextAotGenerator generator = new TestContextAotGenerator (generatedFiles , new RuntimeHints (), false );
143
148
generator .processAheadOfTime (testClasses .stream ());
144
149
@@ -166,7 +171,22 @@ private static void runTestsInAotMode(long expectedNumTests, List<Class<?>> test
166
171
SummaryGeneratingListener listener = new SummaryGeneratingListener ();
167
172
LauncherFactory .create ().execute (request , listener );
168
173
TestExecutionSummary summary = listener .getSummary ();
174
+ if (expectedNumTests < 0 ) {
175
+ summary .printTo (new PrintWriter (System .err ));
176
+ }
169
177
if (summary .getTotalFailureCount () > 0 ) {
178
+ System .err .println ("Failing Test Classes:" );
179
+ summary .getFailures ().stream ()
180
+ .map (Failure ::getTestIdentifier )
181
+ .map (TestIdentifier ::getSource )
182
+ .flatMap (Optional ::stream )
183
+ .filter (ClassSource .class ::isInstance )
184
+ .map (ClassSource .class ::cast )
185
+ .map (AotIntegrationTests ::getJavaClass )
186
+ .flatMap (Optional ::stream )
187
+ .map (Class ::getName )
188
+ .forEach (System .err ::println );
189
+ System .err .println ();
170
190
List <Throwable > exceptions = summary .getFailures ().stream ().map (Failure ::getException ).toList ();
171
191
throw new MultipleFailuresError ("Test execution failures" , exceptions );
172
192
}
@@ -179,6 +199,16 @@ private static void runTestsInAotMode(long expectedNumTests, List<Class<?>> test
179
199
}
180
200
}
181
201
202
+ private static Optional <Class <?>> getJavaClass (ClassSource classSource ) {
203
+ try {
204
+ return Optional .of (classSource .getJavaClass ());
205
+ }
206
+ catch (Exception ex ) {
207
+ // ignore exception
208
+ return Optional .empty ();
209
+ }
210
+ }
211
+
182
212
private static TestClassScanner createTestClassScanner () {
183
213
String classpathRoot = System .getProperty (CLASSPATH_ROOT );
184
214
assertThat (classpathRoot ).as (CLASSPATH_ROOT ).isNotNull ();
0 commit comments