Browse Source

Give better information in case of timeout for JUnit test,as requested in Bug 39946.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@420106 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 19 years ago
parent
commit
0c2d03d031
3 changed files with 12 additions and 20 deletions
  1. +6
    -16
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  2. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl.java
  3. +3
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java

+ 6
- 16
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -1336,7 +1336,7 @@ public class JUnitTask extends Task {
*/ */


private void logTimeout(FormatterElement[] feArray, JUnitTest test) { private void logTimeout(FormatterElement[] feArray, JUnitTest test) {
logVmExit(feArray, test, "Timeout occurred.");
logVmExit(feArray, test, "Timeout occurred. Please note the time in the report does not reflect the time until the timeout.");
} }


/** /**
@@ -1347,7 +1347,7 @@ public class JUnitTask extends Task {
* @since Ant 1.7 * @since Ant 1.7
*/ */
private void logVmCrash(FormatterElement[] feArray, JUnitTest test) { private void logVmCrash(FormatterElement[] feArray, JUnitTest test) {
logVmExit(feArray, test, "Forked Java VM exited abnormally.");
logVmExit(feArray, test, "Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.");
} }


/** /**
@@ -1375,22 +1375,22 @@ public class JUnitTask extends Task {
for (int i = 0; i < feArray.length; i++) { for (int i = 0; i < feArray.length; i++) {
FormatterElement fe = feArray[i]; FormatterElement fe = feArray[i];
File outFile = getOutput(fe, test); File outFile = getOutput(fe, test);
JUnitTaskMirror.JUnitResultFormatterMirror formatter =
JUnitTaskMirror.JUnitResultFormatterMirror formatter =
fe.createFormatter(classLoader); fe.createFormatter(classLoader);
if (outFile != null && formatter != null) { if (outFile != null && formatter != null) {
try { try {
OutputStream out = new FileOutputStream(outFile); OutputStream out = new FileOutputStream(outFile);
addVmExit(test, formatter, out, message);
delegate.addVmExit(test, formatter, out, message);
} catch (IOException e) { } catch (IOException e) {
// ignore // ignore
} }
} }
} }
if (summary) { if (summary) {
JUnitTaskMirror.SummaryJUnitResultFormatterMirror f =
JUnitTaskMirror.SummaryJUnitResultFormatterMirror f =
delegate.newSummaryJUnitResultFormatter(); delegate.newSummaryJUnitResultFormatter();
f.setWithOutAndErr("withoutanderr".equalsIgnoreCase(summaryValue)); f.setWithOutAndErr("withoutanderr".equalsIgnoreCase(summaryValue));
addVmExit(test, f, getDefaultOutput(), message);
delegate.addVmExit(test, f, getDefaultOutput(), message);
} }
} finally { } finally {
if (classLoader != null) { if (classLoader != null) {
@@ -1399,16 +1399,6 @@ public class JUnitTask extends Task {
} }
} }


/**
* Adds the actual error message to the formatter.
* Only used from the logVmExit method.
* @since Ant 1.7
*/
private void addVmExit(JUnitTest test, JUnitTaskMirror.JUnitResultFormatterMirror formatter,
OutputStream out, final String message) {
delegate.addVmExit(test, formatter, out, message);
}

/** /**
* Creates and configures an AntClassLoader instance from the * Creates and configures an AntClassLoader instance from the
* nested classpath element. * nested classpath element.


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl.java View File

@@ -38,9 +38,9 @@ public final class JUnitTaskMirrorImpl implements JUnitTaskMirror {
this.task = task; this.task = task;
} }


public void addVmExit(JUnitTest test, JUnitTaskMirror.JUnitResultFormatterMirror _formatter,
public void addVmExit(JUnitTest test, JUnitTaskMirror.JUnitResultFormatterMirror aFormatter,
OutputStream out, final String message) { OutputStream out, final String message) {
JUnitResultFormatter formatter = (JUnitResultFormatter) _formatter;
JUnitResultFormatter formatter = (JUnitResultFormatter) aFormatter;
formatter.setOutput(out); formatter.setOutput(out);
formatter.startTestSuite(test); formatter.startTestSuite(test);
//the trick to integrating test output to the formatter, is to //the trick to integrating test output to the formatter, is to
@@ -81,7 +81,7 @@ public final class JUnitTaskMirrorImpl implements JUnitTaskMirror {
throw new AssertionFailedError(message); throw new AssertionFailedError(message);
} }


public String getName() {
String getClassName() {
return test.getName(); return test.getName();
} }




+ 3
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelper.java View File

@@ -24,7 +24,6 @@ import junit.framework.TestCase;
/** /**
* Work around for some changes to the public JUnit API between * Work around for some changes to the public JUnit API between
* different JUnit releases. * different JUnit releases.
*
*/ */
public class JUnitVersionHelper { public class JUnitVersionHelper {


@@ -99,6 +98,9 @@ public class JUnitVersionHelper {
*/ */
static String getTestCaseClassName(Test test) { static String getTestCaseClassName(Test test) {
String className = test.getClass().getName(); String className = test.getClass().getName();
if (test instanceof JUnitTaskMirrorImpl.VmExitErrorTest) {
className = ((JUnitTaskMirrorImpl.VmExitErrorTest) test).getClassName();
} else
if (className.equals("junit.framework.JUnit4TestCaseFacade")) { if (className.equals("junit.framework.JUnit4TestCaseFacade")) {
// JUnit 4 wraps solo tests this way. We can extract // JUnit 4 wraps solo tests this way. We can extract
// the original test name with a little hack. // the original test name with a little hack.


Loading…
Cancel
Save