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

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

public class JUnitTestRunner

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.

Author:
Stefan Bodewig, Erik Hatcher

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.
protected  void handleErrorOutput(java.lang.String line)
           
protected  void handleOutput(java.lang.String line)
           
static void main(java.lang.String[] args)
          Entry point for standalone (forked) mode.
 void run()
           
 void startTest(junit.framework.Test t)
          Interface TestListener.
 

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.


endTest

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

A Test is finished.


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.


addError

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

An error occured while running the test.


handleOutput

protected void handleOutput(java.lang.String line)

handleErrorOutput

protected void handleErrorOutput(java.lang.String line)

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 © 1999-2002 Apache Software Foundation. All Rights Reserved.