@@ -49,8 +49,6 @@ public class ConsoleTestExecutor {
4949 private final TestConsoleOutputOptions outputOptions ;
5050 private final Supplier <Launcher > launcherSupplier ;
5151
52- private TestPlan testPlanListeners ;
53-
5452 public ConsoleTestExecutor (TestDiscoveryOptions discoveryOptions , TestConsoleOutputOptions outputOptions ) {
5553 this (discoveryOptions , outputOptions , LauncherFactory ::create );
5654 }
@@ -101,12 +99,11 @@ private TestExecutionSummary executeTests(PrintWriter out, Optional<Path> report
10199 Launcher launcher = launcherSupplier .get ();
102100 SummaryGeneratingListener summaryListener = registerListeners (out , reportsDir , launcher );
103101 LauncherDiscoveryRequest discoveryRequest = new DiscoveryRequestCreator ().toDiscoveryRequest (discoveryOptions );
102+ TestPlanCapturer testPlanCapturer = new TestPlanCapturer ();
104103 launcher .execute (discoveryRequest );
105104 TestExecutionSummary summary = summaryListener .getSummary ();
106105 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 );
110107 }
111108
112109 return summary ;
@@ -180,7 +177,7 @@ private Optional<TestExecutionListener> createXmlWritingListener(PrintWriter out
180177 return reportsDir .map (it -> new LegacyXmlReportGeneratingListener (it , out ));
181178 }
182179
183- private void printSummary (TestExecutionSummary summary , PrintWriter out ) {
180+ private void printSummary (TestExecutionSummary summary , TestPlan testPlan , PrintWriter out ) {
184181 // Otherwise the failures have already been printed in detail
185182 if (EnumSet .of (Details .NONE , Details .SUMMARY , Details .TREE ).contains (outputOptions .getDetails ())) {
186183 summary .printFailuresTo (out );
@@ -198,7 +195,7 @@ private void printSummary(TestExecutionSummary summary, PrintWriter out) {
198195 ValueWrapper actual = assertionFailedError .getActual ();
199196 //apply diff function
200197 if (isCharSequence (expected ) && isCharSequence (actual )) {
201- new DiffPrinter (testPlanListeners ).printDiff (out , expected .getStringRepresentation (),
198+ new DiffPrinter (testPlan ).printDiff (out , expected .getStringRepresentation (),
202199 actual .getStringRepresentation (), failure .getTestIdentifier ());
203200 }
204201 }
@@ -215,4 +212,14 @@ private boolean isCharSequence(ValueWrapper value) {
215212 public interface Factory {
216213 ConsoleTestExecutor create (TestDiscoveryOptions discoveryOptions , TestConsoleOutputOptions outputOptions );
217214 }
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+ }
218225}
0 commit comments