Browse Source

Introduce a "printSummary" attribute on the junitlauncher task to print the test execution summary

master
Jaikiran Pai 7 years ago
parent
commit
047e897775
2 changed files with 18 additions and 0 deletions
  1. +8
    -0
      manual/Tasks/junitlauncher.html
  2. +10
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTask.java

+ 8
- 0
manual/Tasks/junitlauncher.html View File

@@ -141,6 +141,14 @@
</td> </td>
<td>No</td> <td>No</td>
</tr> </tr>
<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.
</td>
<td>No; defaults to <code>false</code></td>
</tr>
</table> </table>


<h3 id="nested">Nested Elements</h3> <h3 id="nested">Nested Elements</h3>


+ 10
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/JUnitLauncherTask.java View File

@@ -21,6 +21,7 @@ import java.io.OutputStream;
import java.io.PipedInputStream; import java.io.PipedInputStream;
import java.io.PipedOutputStream; import java.io.PipedOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
@@ -57,6 +58,7 @@ public class JUnitLauncherTask extends Task {
private Path classPath; private Path classPath;
private boolean haltOnFailure; private boolean haltOnFailure;
private String failureProperty; private String failureProperty;
private boolean printSummary;
private final List<TestDefinition> tests = new ArrayList<>(); private final List<TestDefinition> tests = new ArrayList<>();
private final List<ListenerDefinition> listeners = new ArrayList<>(); private final List<ListenerDefinition> listeners = new ArrayList<>();


@@ -172,6 +174,10 @@ public class JUnitLauncherTask extends Task {
this.failureProperty = failureProperty; this.failureProperty = failureProperty;
} }


public void setPrintSummary(final boolean printSummary) {
this.printSummary = printSummary;
}

private void preConfigure(final TestDefinition test) { private void preConfigure(final TestDefinition test) {
if (test.getHaltOnFailure() == null) { if (test.getHaltOnFailure() == null) {
test.setHaltOnFailure(this.haltOnFailure); test.setHaltOnFailure(this.haltOnFailure);
@@ -267,6 +273,10 @@ public class JUnitLauncherTask extends Task {
} }


private void handleTestExecutionCompletion(final TestDefinition test, final TestExecutionSummary summary) { private void handleTestExecutionCompletion(final TestDefinition test, final TestExecutionSummary summary) {
if (printSummary) {
// print the summary to System.out
summary.printTo(new PrintWriter(System.out, true));
}
final boolean hasTestFailures = summary.getTestsFailedCount() != 0; final boolean hasTestFailures = summary.getTestsFailedCount() != 0;
try { try {
if (hasTestFailures && test.getFailureProperty() != null) { if (hasTestFailures && test.getFailureProperty() != null) {


Loading…
Cancel
Save