This is an automated email from the ASF dual-hosted git repository. jaikiran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push: new 635ccfb bz-64836 junitlauncher - Print a more informative and instant summary for tests 635ccfb is described below commit 635ccfb5e4316be952241aae26cc36f3aa38f79b Author: Jaikiran Pai <jaiki...@apache.org> AuthorDate: Fri Jan 15 19:09:06 2021 +0530 bz-64836 junitlauncher - Print a more informative and instant summary for tests --- manual/Tasks/junitlauncher.html | 5 +-- .../optional/junitlauncher/LauncherSupport.java | 37 ++++++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/manual/Tasks/junitlauncher.html b/manual/Tasks/junitlauncher.html index 4a96e71..f8899bb 100644 --- a/manual/Tasks/junitlauncher.html +++ b/manual/Tasks/junitlauncher.html @@ -166,8 +166,9 @@ <tr> <td>printSummary</td> <td>If the value is set to <code>true</code> then this task, upon completion of the test execution, - prints the summary of the execution to <code>System.out</code>. The summary itself is generated - by the JUnit 5 platform and not by this task. + prints the summary of the execution to <code>System.out</code>. Starting Ant 1.10.10, unlike + in previous versions, this task itself generates the summary instead of using the one generated + by the JUnit 5 platform. </td> <td>No; defaults to <code>false</code></td> </tr> diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java index 3b56016..66308dc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java @@ -37,6 +37,7 @@ import org.junit.platform.launcher.Launcher; import org.junit.platform.launcher.LauncherDiscoveryRequest; import org.junit.platform.launcher.TagFilter; import org.junit.platform.launcher.TestExecutionListener; +import org.junit.platform.launcher.TestIdentifier; import org.junit.platform.launcher.TestPlan; import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; import org.junit.platform.launcher.core.LauncherFactory; @@ -49,7 +50,6 @@ import java.io.OutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.PrintStream; -import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -128,7 +128,7 @@ public class LauncherSupport { final List<TestExecutionListener> testExecutionListeners = new ArrayList<>(); // a listener that we always put at the front of list of listeners // for this request. - final Listener firstListener = new Listener(); + final Listener firstListener = new Listener(System.out); // we always enroll the summary generating listener, to the request, so that we // get to use some of the details of the summary for our further decision making testExecutionListeners.add(firstListener); @@ -301,10 +301,6 @@ public class LauncherSupport { } private void handleTestExecutionCompletion(final TestDefinition test, final TestExecutionSummary summary) { - if (this.launchDefinition.isPrintSummary()) { - // print the summary to System.out - summary.printTo(new PrintWriter(System.out, true)); - } final boolean hasTestFailures = summary.getTotalFailureCount() != 0; if (hasTestFailures) { // keep track of the test failure(s) for the entire launched instance @@ -596,12 +592,41 @@ public class LauncherSupport { } private final class Listener extends SummaryGeneratingListener { + private final PrintStream originalSysOut; + private Optional<SwitchedStreamHandle> switchedSysOutHandle; private Optional<SwitchedStreamHandle> switchedSysErrHandle; + private Listener(final PrintStream originalSysOut) { + this.originalSysOut = originalSysOut; + } + + @Override + public void executionStarted(final TestIdentifier testIdentifier) { + super.executionStarted(testIdentifier); + AbstractJUnitResultFormatter.isTestClass(testIdentifier).ifPresent(testClass -> { + this.originalSysOut.println("Running " + testClass.getClassName()); + }); + } + @Override public void testPlanExecutionFinished(final TestPlan testPlan) { super.testPlanExecutionFinished(testPlan); + if (launchDefinition.isPrintSummary()) { + final TestExecutionSummary summary = this.getSummary(); + // Keep the summary as close to as the old junit task summary + // tests run, failed, skipped, duration + final StringBuilder sb = new StringBuilder("Tests run: "); + sb.append(summary.getTestsStartedCount()); + sb.append(", Failures: "); + sb.append(summary.getTestsFailedCount()); + sb.append(", Skipped: "); + sb.append(summary.getTestsSkippedCount()); + sb.append(", Time elapsed: "); + sb.append((summary.getTimeFinished() - summary.getTimeStarted()) / 1000f); + sb.append(" sec"); + this.originalSysOut.println(sb.toString()); + } // now that the test plan execution is finished, close the switched sysout/syserr output streams // and wait for the sysout and syserr content delivery, to result formatters, to finish if (this.switchedSysOutHandle.isPresent()) {