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.

Otherwise all public methods starting with "test" and taking no argument will be run.

Summary output is generated at the end.

Author:
Stefan Bodewig

Field Summary
static int ERRORS
          An error occured.
static int FAILURES
          Some tests failed.
static int SUCCESS
          No problems with this test.
 
Constructor Summary
JUnitTestRunner(JUnitTest test, boolean haltOnError, boolean haltOnFailure)
          Constructor for fork=true or when the user hasn't specified a classpath.
JUnitTestRunner(JUnitTest test, boolean haltOnError, 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.
 int getRetCode()
          Returns what System.exit() would return in the standalone version.
static void main(java.lang.String[] args)
          Entry point for standalone (forked) mode.
 void 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.

FAILURES

public static final int FAILURES
Some tests failed.

ERRORS

public static final int ERRORS
An error occured.
Constructor Detail

JUnitTestRunner

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

JUnitTestRunner

public JUnitTestRunner(JUnitTest test,
                       boolean haltOnError,
                       boolean haltOnFailure,
                       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.

Specified by:
addFailure in interface junit.framework.TestListener

addFailure

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

A Test failed.


addError

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

An error occured while running the test.

Specified by:
addError in interface junit.framework.TestListener

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


Copyright © 2000 Apache Software Foundation. All Rights Reserved.