Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture TestPlan in separate listener #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public class ConsoleTestExecutor {
private final TestConsoleOutputOptions outputOptions;
private final Supplier<Launcher> launcherSupplier;

private TestPlan testPlanListeners;

public ConsoleTestExecutor(TestDiscoveryOptions discoveryOptions, TestConsoleOutputOptions outputOptions) {
this(discoveryOptions, outputOptions, LauncherFactory::create);
}
Expand Down Expand Up @@ -101,12 +99,13 @@ private TestExecutionSummary executeTests(PrintWriter out, Optional<Path> report
Launcher launcher = launcherSupplier.get();
SummaryGeneratingListener summaryListener = registerListeners(out, reportsDir, launcher);
LauncherDiscoveryRequest discoveryRequest = new DiscoveryRequestCreator().toDiscoveryRequest(discoveryOptions);
launcher.execute(discoveryRequest);

TestPlanCapturer testPlanCapturer = new TestPlanCapturer();
launcher.execute(discoveryRequest, testPlanCapturer);

TestExecutionSummary summary = summaryListener.getSummary();
if (summary.getTotalFailureCount() > 0 || outputOptions.getDetails() != Details.NONE) {
//get testPlan from summaryListener
testPlanListeners = summaryListener.getTestPlan();
printSummary(summary, out);
printSummary(summary, testPlanCapturer.testPlan, out);
}

return summary;
Expand Down Expand Up @@ -180,7 +179,7 @@ private Optional<TestExecutionListener> createXmlWritingListener(PrintWriter out
return reportsDir.map(it -> new LegacyXmlReportGeneratingListener(it, out));
}

private void printSummary(TestExecutionSummary summary, PrintWriter out) {
private void printSummary(TestExecutionSummary summary, TestPlan testPlan, PrintWriter out) {
// Otherwise the failures have already been printed in detail
if (EnumSet.of(Details.NONE, Details.SUMMARY, Details.TREE).contains(outputOptions.getDetails())) {
summary.printFailuresTo(out);
Expand All @@ -198,7 +197,7 @@ private void printSummary(TestExecutionSummary summary, PrintWriter out) {
ValueWrapper actual = assertionFailedError.getActual();
//apply diff function
if (isCharSequence(expected) && isCharSequence(actual)) {
new DiffPrinter(testPlanListeners).printDiff(out, expected.getStringRepresentation(),
new DiffPrinter(testPlan).printDiff(out, expected.getStringRepresentation(),
actual.getStringRepresentation(), failure.getTestIdentifier());
}
}
Expand All @@ -215,4 +214,14 @@ private boolean isCharSequence(ValueWrapper value) {
public interface Factory {
ConsoleTestExecutor create(TestDiscoveryOptions discoveryOptions, TestConsoleOutputOptions outputOptions);
}

private static class TestPlanCapturer implements TestExecutionListener {

private TestPlan testPlan;

@Override
public void testPlanExecutionStarted(TestPlan testPlan) {
this.testPlan = testPlan;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ public TestExecutionSummary getSummary() {
return this.summary;
}

/**
* Get the testPlan of this listener.
*/
public TestPlan getTestPlan() {
return testPlan;
}

@Override
public void testPlanExecutionStarted(TestPlan testPlan) {
this.testPlan = testPlan;
Expand Down