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@420102 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 19 years ago
parent
commit
3cf51fd6de
2 changed files with 34 additions and 14 deletions
  1. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  2. +32
    -12
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskMirrorImpl.java

+ 2
- 2
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) {
logVmExit(feArray, test, "Timeout occurred");
logVmExit(feArray, test, "Timeout occurred.");
}

/**
@@ -1347,7 +1347,7 @@ public class JUnitTask extends Task {
* @since Ant 1.7
*/
private void logVmCrash(FormatterElement[] feArray, JUnitTest test) {
logVmExit(feArray, test, "forked Java VM exited abnormally");
logVmExit(feArray, test, "Forked Java VM exited abnormally.");
}

/**


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

@@ -19,7 +19,7 @@ package org.apache.tools.ant.taskdefs.optional.junit;

import java.io.OutputStream;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import org.apache.tools.ant.AntClassLoader;

@@ -31,28 +31,22 @@ import org.apache.tools.ant.AntClassLoader;
* @since 1.7
*/
public final class JUnitTaskMirrorImpl implements JUnitTaskMirror {
private final JUnitTask task;
public JUnitTaskMirrorImpl(JUnitTask task) {
this.task = task;
}
public void addVmExit(JUnitTest test, JUnitTaskMirror.JUnitResultFormatterMirror _formatter,
OutputStream out, final String message) {
JUnitResultFormatter formatter = (JUnitResultFormatter) _formatter;
formatter.setOutput(out);
formatter.startTestSuite(test);
//the trick to integrating test output to the formatter, is to
//create a special test class that asserts an error
//and tell the formatter that it raised.
Test t = new Test() {
public int countTestCases() { return 1; }
public void run(TestResult r) {
throw new AssertionFailedError(message);
}
};
TestCase t = new VmExitErrorTest(message, test);
formatter.startTest(t);
formatter.addError(t, new AssertionFailedError(message));
formatter.endTestSuite(test);
@@ -68,5 +62,31 @@ public final class JUnitTaskMirrorImpl implements JUnitTaskMirror {
public JUnitTaskMirror.SummaryJUnitResultFormatterMirror newSummaryJUnitResultFormatter() {
return new SummaryJUnitResultFormatter();
}

static class VmExitErrorTest extends TestCase {

private String message;
private JUnitTest test;

VmExitErrorTest(String aMessage, JUnitTest anOriginalTest) {
message = aMessage;
test = anOriginalTest;
}

public int countTestCases() {
return 1;
}

public void run(TestResult r) {
throw new AssertionFailedError(message);
}

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

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

Loading…
Cancel
Save