public class JUnitTestRunner extends java.lang.Object implements junit.framework.TestListener, JUnitTaskMirror.JUnitTestRunnerMirror
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.
ERRORS, FAILURES, IGNORED_FILE_NAME, SUCCESS
Constructor and Description |
---|
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,
boolean showOutput,
boolean logTestListenerEvents)
Constructor for fork=true or when the user hasn't specified a
classpath.
|
JUnitTestRunner(JUnitTest test,
boolean haltOnError,
boolean filtertrace,
boolean haltOnFailure,
boolean showOutput,
boolean logTestListenerEvents,
java.lang.ClassLoader loader)
Constructor to use when the user has specified a classpath.
|
JUnitTestRunner(JUnitTest test,
boolean haltOnError,
boolean filtertrace,
boolean haltOnFailure,
boolean showOutput,
java.lang.ClassLoader loader)
Constructor to use when the user has specified a classpath.
|
JUnitTestRunner(JUnitTest test,
boolean haltOnError,
boolean filtertrace,
boolean haltOnFailure,
java.lang.ClassLoader loader)
Constructor to use when the user has specified a classpath.
|
JUnitTestRunner(JUnitTest test,
java.lang.String[] methods,
boolean haltOnError,
boolean filtertrace,
boolean haltOnFailure,
boolean showOutput,
boolean logTestListenerEvents)
Constructor for fork=true or when the user hasn't specified a
classpath.
|
JUnitTestRunner(JUnitTest test,
java.lang.String[] methods,
boolean haltOnError,
boolean filtertrace,
boolean haltOnFailure,
boolean showOutput,
boolean logTestListenerEvents,
java.lang.ClassLoader loader)
Constructor to use when the user has specified a classpath.
|
Modifier and Type | Method and Description |
---|---|
void |
addError(junit.framework.Test test,
java.lang.Throwable t)
Interface TestListener.
|
void |
addFailure(junit.framework.Test test,
junit.framework.AssertionFailedError t)
Interface TestListener for JUnit > 3.4.
|
void |
addFailure(junit.framework.Test test,
java.lang.Throwable t)
Interface TestListener for JUnit <= 3.4.
|
void |
addFormatter(JUnitResultFormatter f)
Add a formatter.
|
void |
addFormatter(JUnitTaskMirror.JUnitResultFormatterMirror f)
Add a formatter to the test.
|
void |
endTest(junit.framework.Test test)
Interface TestListener.
|
static java.lang.String |
filterStack(java.lang.String stack)
Filters stack frames from internal JUnit and Ant classes
|
static java.lang.String |
getFilteredTrace(java.lang.Throwable t)
Returns a filtered stack trace.
|
int |
getRetCode()
Returns what System.exit() would return in the standalone version.
|
void |
handleErrorFlush(java.lang.String output)
Handle output sent to System.err.
|
void |
handleErrorOutput(java.lang.String output)
Handle output sent to System.err.
|
void |
handleFlush(java.lang.String output)
Handle output sent to System.out.
|
int |
handleInput(byte[] buffer,
int offset,
int length)
Handle input.
|
void |
handleOutput(java.lang.String output)
Handle a string destined for standard output.
|
static void |
main(java.lang.String[] args)
Entry point for standalone (forked) mode.
|
void |
run()
Run the test.
|
void |
setPermissions(Permissions permissions)
Permissions for the test run.
|
void |
startTest(junit.framework.Test t)
Interface TestListener.
|
public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure)
test
- the test to run.haltOnError
- whether to stop the run if an error is found.filtertrace
- whether to filter junit.*.* stack frames out of exceptionshaltOnFailure
- whether to stop the run if failure is found.public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput)
test
- the test to run.haltOnError
- whether to stop the run if an error is found.filtertrace
- whether to filter junit.*.* stack frames out of exceptionshaltOnFailure
- whether to stop the run if failure is found.showOutput
- whether to send output to System.out/.err as well as formatters.public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput, boolean logTestListenerEvents)
test
- the test to run.haltOnError
- whether to stop the run if an error is found.filtertrace
- whether to filter junit.*.* stack frames out of exceptionshaltOnFailure
- whether to stop the run if failure is found.showOutput
- whether to send output to System.out/.err as well as formatters.logTestListenerEvents
- whether to print TestListener events.public JUnitTestRunner(JUnitTest test, java.lang.String[] methods, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput, boolean logTestListenerEvents)
test
- the test to run.methods
- names of methods of the test to be executed.haltOnError
- whether to stop the run if an error is found.filtertrace
- whether to filter junit.*.* stack frames out of exceptionshaltOnFailure
- whether to stop the run if failure is found.showOutput
- whether to send output to System.out/.err as well as formatters.logTestListenerEvents
- whether to print TestListener events.public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, java.lang.ClassLoader loader)
test
- the test to run.haltOnError
- whether to stop the run if an error is found.filtertrace
- whether to filter junit.*.* stack frames out of exceptionshaltOnFailure
- whether to stop the run if failure is found.loader
- the classloader to use running the test.public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput, java.lang.ClassLoader loader)
test
- the test to run.haltOnError
- whether to stop the run if an error is found.filtertrace
- whether to filter junit.*.* stack frames out of exceptionshaltOnFailure
- whether to stop the run if failure is found.showOutput
- whether to send output to System.out/.err as well as formatters.loader
- the classloader to use running the test.public JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput, boolean logTestListenerEvents, java.lang.ClassLoader loader)
test
- the test to run.haltOnError
- whether to stop the run if an error is found.filtertrace
- whether to filter junit.*.* stack frames out of exceptionshaltOnFailure
- whether to stop the run if failure is found.showOutput
- whether to send output to System.out/.err as well as formatters.logTestListenerEvents
- whether to print TestListener events.loader
- the classloader to use running the test.public JUnitTestRunner(JUnitTest test, java.lang.String[] methods, boolean haltOnError, boolean filtertrace, boolean haltOnFailure, boolean showOutput, boolean logTestListenerEvents, java.lang.ClassLoader loader)
public void run()
run
in interface JUnitTaskMirror.JUnitTestRunnerMirror
public int getRetCode()
getRetCode
in interface JUnitTaskMirror.JUnitTestRunnerMirror
public void startTest(junit.framework.Test t)
A new Test is started.
startTest
in interface junit.framework.TestListener
t
- the test.public void endTest(junit.framework.Test test)
A Test is finished.
endTest
in interface junit.framework.TestListener
test
- the test.public void addFailure(junit.framework.Test test, java.lang.Throwable t)
A Test failed.
test
- the test.t
- the exception thrown by the test.public void addFailure(junit.framework.Test test, junit.framework.AssertionFailedError t)
A Test failed.
addFailure
in interface junit.framework.TestListener
test
- the test.t
- the assertion thrown by the test.public void addError(junit.framework.Test test, java.lang.Throwable t)
An error occurred while running the test.
addError
in interface junit.framework.TestListener
test
- the test.t
- the error thrown by the test.public void setPermissions(Permissions permissions)
setPermissions
in interface JUnitTaskMirror.JUnitTestRunnerMirror
permissions
- the permissions to use.public void handleOutput(java.lang.String output)
handleOutput
in interface JUnitTaskMirror.JUnitTestRunnerMirror
output
- the string to outputpublic int handleInput(byte[] buffer, int offset, int length) throws java.io.IOException
handleInput
in interface JUnitTaskMirror.JUnitTestRunnerMirror
buffer
- not used.offset
- not used.length
- not used.java.io.IOException
- never.Task.handleInput(byte[], int, int)
public void handleErrorOutput(java.lang.String output)
handleErrorOutput
in interface JUnitTaskMirror.JUnitTestRunnerMirror
output
- output for System.errpublic void handleFlush(java.lang.String output)
handleFlush
in interface JUnitTaskMirror.JUnitTestRunnerMirror
output
- output for System.out.public void handleErrorFlush(java.lang.String output)
handleErrorFlush
in interface JUnitTaskMirror.JUnitTestRunnerMirror
output
- coming from System.errpublic void addFormatter(JUnitResultFormatter f)
f
- the formatter to add.public void addFormatter(JUnitTaskMirror.JUnitResultFormatterMirror f)
addFormatter
in interface JUnitTaskMirror.JUnitTestRunnerMirror
f
- the formatter to use.public static void main(java.lang.String[] args) throws java.io.IOException
key | description | default value |
---|---|---|
haltOnError | halt test on errors? | false |
haltOnFailure | halt test on failures? | false |
formatter | A JUnitResultFormatter given as classname,filename. If filename is ommitted, System.out is assumed. | none |
showoutput | send output to System.err/.out as well as to the formatters? | false |
logtestlistenerevents | log TestListener events to System.out. | false |
methods | Comma-separated list of names of individual test methods to execute. | null |
args
- the command line arguments.java.io.IOException
- on error.public static java.lang.String getFilteredTrace(java.lang.Throwable t)
t
- the exception to filter.public static java.lang.String filterStack(java.lang.String stack)
stack
- the stack trace to filter.