From 866b754aadc0d8f482a569e0fd9e136dd7df824c Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Mon, 15 Nov 2004 10:41:43 +0000 Subject: [PATCH] Junit task -- display suite first PR: 31962 Obtained from: Kevin Jackson git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277033 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 5 +++- .../junit/BriefJUnitResultFormatter.java | 20 +++++++++----- .../junit/PlainJUnitResultFormatter.java | 26 ++++++++++++++----- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 2a2277d66..91e8481e6 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -81,7 +81,10 @@ Other changes: * New task can retrieve library files from a maven repository. * unzip/unwar/unjar/untar now supports a nested mapper, which lets you unzip - in useful ways. + in useful ways. + +* Junit task -- display suite first. + Bugzilla report 31962. Changes from Ant 1.6.2 to current Ant 1.6 CVS version ===================================================== diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java index c75baaa84..ee32e0af8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/BriefJUnitResultFormatter.java @@ -94,19 +94,27 @@ public class BriefJUnitResultFormatter implements JUnitResultFormatter { /** * The whole testsuite started. + * @param suite the test suite */ - public void startTestSuite(JUnitTest suite) throws BuildException { + public void startTestSuite(JUnitTest suite) { + if (output == null) { + return; // Quick return - no output do nothing. + } + String newLine = System.getProperty("line.separator"); + StringBuffer sb = new StringBuffer("Testsuite: "); + sb.append(suite.getName()); + sb.append(newLine); + output.write(sb.toString()); + output.flush(); } /** * The whole testsuite ended. + * @param suite the test suite */ - public void endTestSuite(JUnitTest suite) throws BuildException { + public void endTestSuite(JUnitTest suite) { String newLine = System.getProperty("line.separator"); - StringBuffer sb = new StringBuffer("Testsuite: "); - sb.append(suite.getName()); - sb.append(newLine); - sb.append("Tests run: "); + StringBuffer sb = new StringBuffer("Tests run: "); sb.append(suite.runCount()); sb.append(", Failures: "); sb.append(suite.failureCount()); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java index 5cdcd95e8..ffcc8aab2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/PlainJUnitResultFormatter.java @@ -81,20 +81,34 @@ public class PlainJUnitResultFormatter implements JUnitResultFormatter { } /** - * Empty. + * The whole testsuite started. + * @param suite the test suite + * @throws BuildException if unable to write the output */ - public void startTestSuite(JUnitTest suite) { + public void startTestSuite(JUnitTest suite) throws BuildException { + if (out == null) { + return; // Quick return - no output do nothing. + } + String newLine = System.getProperty("line.separator"); + StringBuffer sb = new StringBuffer("Testsuite: "); + sb.append(suite.getName()); + sb.append(newLine); + try { + out.write(sb.toString().getBytes()); + out.flush(); + } catch (IOException ex) { + throw new BuildException("Unable to write output", ex); + } } /** * The whole testsuite ended. + * @param suite the test suite + * @throws BuildException if unable to write the output */ public void endTestSuite(JUnitTest suite) throws BuildException { String newLine = System.getProperty("line.separator"); - StringBuffer sb = new StringBuffer("Testsuite: "); - sb.append(suite.getName()); - sb.append(newLine); - sb.append("Tests run: "); + StringBuffer sb = new StringBuffer("Tests run: "); sb.append(suite.runCount()); sb.append(", Failures: "); sb.append(suite.failureCount());