org.apache.tools.ant.taskdefs.optional.junit

Class JUnitTestRunner

public class JUnitTestRunner extends Object implements TestListener

Simple Testrunner for JUnit that runs all tests of a testsuite.

This TestRunner expects a name of a TestCase class as its argument. If this class provides a static suite() method it will be called and the resulting Test will be run. So, the signature should be


     public static junit.framework.Test suite()
 

If no such method exists, all public methods starting with "test" and taking no argument will be run.

Summary output is generated at the end.

Since: Ant 1.2

Field Summary
static intERRORS
An error occurred.
static intFAILURES
Some tests failed.
static StringIGNORED_FILE_NAME
Used in formatter arguments as a placeholder for the basename of the output file (which gets replaced by a test specific output file name later).
static intSUCCESS
No problems with this test.
Constructor Summary
JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure)
Constructor for fork=true or when the user hasn't specified a classpath.
JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput)
Constructor for fork=true or when the user hasn't specified a classpath.
JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, ClassLoader loader)
Constructor to use when the user has specified a classpath.
JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput, ClassLoader loader)
Constructor to use when the user has specified a classpath.
Method Summary
voidaddError(Test test, Throwable t)
Interface TestListener.
voidaddFailure(Test test, Throwable t)
Interface TestListener for JUnit <= 3.4.
voidaddFailure(Test test, AssertionFailedError t)
Interface TestListener for JUnit > 3.4.
voidaddFormatter(JUnitResultFormatter f)
voidendTest(Test test)
Interface TestListener.
static StringfilterStack(String stack)
Filters stack frames from internal JUnit and Ant classes
static StringgetFilteredTrace(Throwable t)
Returns a filtered stack trace.
intgetRetCode()
Returns what System.exit() would return in the standalone version.
protected voidhandleErrorFlush(String output)
protected voidhandleErrorOutput(String output)
protected voidhandleFlush(String output)
protected inthandleInput(byte[] buffer, int offset, int length)
protected voidhandleOutput(String output)
static voidmain(String[] args)
Entry point for standalone (forked) mode.
voidrun()
voidsetPermissions(Permissions permissions)
Permissions for the test run.
voidstartTest(Test t)
Interface TestListener.

Field Detail

ERRORS

public static final int ERRORS
An error occurred.

FAILURES

public static final int FAILURES
Some tests failed.

IGNORED_FILE_NAME

public static final String IGNORED_FILE_NAME
Used in formatter arguments as a placeholder for the basename of the output file (which gets replaced by a test specific output file name later).

Since: Ant 1.6.3

SUCCESS

public static final int SUCCESS
No problems with this test.

Constructor Detail

JUnitTestRunner

public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure)
Constructor for fork=true or when the user hasn't specified a classpath.

JUnitTestRunner

public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput)
Constructor for fork=true or when the user hasn't specified a classpath.

JUnitTestRunner

public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, ClassLoader loader)
Constructor to use when the user has specified a classpath.

JUnitTestRunner

public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput, ClassLoader loader)
Constructor to use when the user has specified a classpath.

Method Detail

addError

public void addError(Test test, Throwable t)
Interface TestListener.

An error occurred while running the test.

addFailure

public void addFailure(Test test, Throwable t)
Interface TestListener for JUnit <= 3.4.

A Test failed.

addFailure

public void addFailure(Test test, AssertionFailedError t)
Interface TestListener for JUnit > 3.4.

A Test failed.

addFormatter

public void addFormatter(JUnitResultFormatter f)

endTest

public void endTest(Test test)
Interface TestListener.

A Test is finished.

filterStack

public static String filterStack(String stack)
Filters stack frames from internal JUnit and Ant classes

getFilteredTrace

public static String getFilteredTrace(Throwable t)
Returns a filtered stack trace. This is ripped out of junit.runner.BaseTestRunner.

getRetCode

public int getRetCode()
Returns what System.exit() would return in the standalone version.

Returns: 2 if errors occurred, 1 if tests failed else 0.

handleErrorFlush

protected void handleErrorFlush(String output)

handleErrorOutput

protected void handleErrorOutput(String output)

handleFlush

protected void handleFlush(String output)

handleInput

protected int handleInput(byte[] buffer, int offset, int length)

Since: Ant 1.6

See Also: (byte[], int, int)

handleOutput

protected void handleOutput(String output)

main

public static void main(String[] args)
Entry point for standalone (forked) mode. Parameters: testcaseclassname plus parameters in the format key=value, none of which is required.
keydescriptiondefault value
haltOnErrorhalt test on errors?false
haltOnFailurehalt test on failures?false
formatterA JUnitResultFormatter given as classname,filename. If filename is ommitted, System.out is assumed.none
showoutputsend output to System.err/.out as well as to the formatters?false

run

public void run()

setPermissions

public void setPermissions(Permissions permissions)
Permissions for the test run.

Parameters: permissions

Since: Ant 1.6

startTest

public void startTest(Test t)
Interface TestListener.

A new Test is started.

Copyright