@@ -49,8 +49,6 @@ public class ConsoleTestExecutor {
49
49
private final TestConsoleOutputOptions outputOptions ;
50
50
private final Supplier <Launcher > launcherSupplier ;
51
51
52
- private TestPlan testPlanListeners ;
53
-
54
52
public ConsoleTestExecutor (TestDiscoveryOptions discoveryOptions , TestConsoleOutputOptions outputOptions ) {
55
53
this (discoveryOptions , outputOptions , LauncherFactory ::create );
56
54
}
@@ -101,12 +99,11 @@ private TestExecutionSummary executeTests(PrintWriter out, Optional<Path> report
101
99
Launcher launcher = launcherSupplier .get ();
102
100
SummaryGeneratingListener summaryListener = registerListeners (out , reportsDir , launcher );
103
101
LauncherDiscoveryRequest discoveryRequest = new DiscoveryRequestCreator ().toDiscoveryRequest (discoveryOptions );
102
+ TestPlanCapturer testPlanCapturer = new TestPlanCapturer ();
104
103
launcher .execute (discoveryRequest );
105
104
TestExecutionSummary summary = summaryListener .getSummary ();
106
105
if (summary .getTotalFailureCount () > 0 || outputOptions .getDetails () != Details .NONE ) {
107
- //get testPlan from summaryListener
108
- testPlanListeners = summaryListener .getTestPlan ();
109
- printSummary (summary , out );
106
+ printSummary (summary , testPlanCapturer .testPlan , out );
110
107
}
111
108
112
109
return summary ;
@@ -180,7 +177,7 @@ private Optional<TestExecutionListener> createXmlWritingListener(PrintWriter out
180
177
return reportsDir .map (it -> new LegacyXmlReportGeneratingListener (it , out ));
181
178
}
182
179
183
- private void printSummary (TestExecutionSummary summary , PrintWriter out ) {
180
+ private void printSummary (TestExecutionSummary summary , TestPlan testPlan , PrintWriter out ) {
184
181
// Otherwise the failures have already been printed in detail
185
182
if (EnumSet .of (Details .NONE , Details .SUMMARY , Details .TREE ).contains (outputOptions .getDetails ())) {
186
183
summary .printFailuresTo (out );
@@ -198,7 +195,7 @@ private void printSummary(TestExecutionSummary summary, PrintWriter out) {
198
195
ValueWrapper actual = assertionFailedError .getActual ();
199
196
//apply diff function
200
197
if (isCharSequence (expected ) && isCharSequence (actual )) {
201
- new DiffPrinter (testPlanListeners ).printDiff (out , expected .getStringRepresentation (),
198
+ new DiffPrinter (testPlan ).printDiff (out , expected .getStringRepresentation (),
202
199
actual .getStringRepresentation (), failure .getTestIdentifier ());
203
200
}
204
201
}
@@ -215,4 +212,14 @@ private boolean isCharSequence(ValueWrapper value) {
215
212
public interface Factory {
216
213
ConsoleTestExecutor create (TestDiscoveryOptions discoveryOptions , TestConsoleOutputOptions outputOptions );
217
214
}
215
+
216
+ private static class TestPlanCapturer implements TestExecutionListener {
217
+
218
+ private TestPlan testPlan ;
219
+
220
+ @ Override
221
+ public void testPlanExecutionStarted (TestPlan testPlan ) {
222
+ this .testPlan = testPlan ;
223
+ }
224
+ }
218
225
}
0 commit comments