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

java.lang.Object
  |
  +--org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner
All Implemented Interfaces:
junit.framework.TestListener

public class JUnitTestRunner
extends java.lang.Object
implements junit.framework.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 int ERRORS
          An error occurred.
static int FAILURES
          Some tests failed.
static int SUCCESS
          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, 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.
 
Method Summary
 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)
           
 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.
protected  void handleErrorFlush(java.lang.String output)
           
protected  void handleErrorOutput(java.lang.String output)
           
protected  void handleFlush(java.lang.String output)
           
protected  int handleInput(byte[] buffer, int offset, int length)
           
protected  void handleOutput(java.lang.String output)
           
static void main(java.lang.String[] args)
          Entry point for standalone (forked) mode.
 void run()
           
 void setPermissions(Permissions permissions)
          Permissions for the test run.
 void startTest(junit.framework.Test t)
          Interface TestListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUCCESS

public static final int SUCCESS
No problems with this test.

See Also:
Constant Field Values

FAILURES

public static final int FAILURES
Some tests failed.

See Also:
Constant Field Values

ERRORS

public static final int ERRORS
An error occurred.

See Also:
Constant Field Values
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,
                       java.lang.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,
                       java.lang.ClassLoader loader)
Constructor to use when the user has specified a classpath.

Method Detail

run

public void run()

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.

startTest

public void startTest(junit.framework.Test t)
Interface TestListener.

A new Test is started.

Specified by:
startTest in interface junit.framework.TestListener

endTest

public void endTest(junit.framework.Test test)
Interface TestListener.

A Test is finished.

Specified by:
endTest in interface junit.framework.TestListener

addFailure

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

A Test failed.


addFailure

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

A Test failed.

Specified by:
addFailure in interface junit.framework.TestListener

addError

public void addError(junit.framework.Test test,
                     java.lang.Throwable t)
Interface TestListener.

An error occurred while running the test.

Specified by:
addError in interface junit.framework.TestListener

setPermissions

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

Parameters:
permissions -
Since:
Ant 1.6

handleOutput

protected void handleOutput(java.lang.String output)

handleInput

protected int handleInput(byte[] buffer,
                          int offset,
                          int length)
                   throws java.io.IOException
java.io.IOException
Since:
Ant 1.6
See Also:
Task#handleInput(byte[], int, int)

handleErrorOutput

protected void handleErrorOutput(java.lang.String output)

handleFlush

protected void handleFlush(java.lang.String output)

handleErrorFlush

protected void handleErrorFlush(java.lang.String output)

addFormatter

public void addFormatter(JUnitResultFormatter f)

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
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

java.io.IOException

getFilteredTrace

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


filterStack

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



Copyright © 2000-2004 Apache Software Foundation. All Rights Reserved.