junit.textui
Class TestRunner

java.lang.Object
  extended by junit.runner.BaseTestRunner
      extended by junit.textui.TestRunner
All Implemented Interfaces:
TestListener

public class TestRunner
extends BaseTestRunner

A command line based tool to run tests.

 java junit.textui.TestRunner [-wait] TestCaseClass
 

TestRunner expects the name of a TestCase class as argument. If this class defines a static suite method it will be invoked and the returned test is run. Otherwise all the methods starting with "test" having no arguments are run.

When the wait command line argument is given TestRunner waits until the users types RETURN.

TestRunner prints a trace as the tests are executed followed by a summary at the end.


Field Summary
static int EXCEPTION_EXIT
           
static int FAILURE_EXIT
           
static int SUCCESS_EXIT
           
 
Fields inherited from class junit.runner.BaseTestRunner
SUITE_METHODNAME
 
Constructor Summary
TestRunner()
          Constructs a TestRunner.
TestRunner(PrintStream writer)
          Constructs a TestRunner using the given stream for all the output
TestRunner(ResultPrinter printer)
          Constructs a TestRunner using the given ResultPrinter all the output
 
Method Summary
 TestResult doRun(Test test)
           
 TestResult doRun(Test suite, boolean wait)
           
static void main(String[] args)
           
static void run(Class<? extends TestCase> testClass)
          Runs a suite extracted from a TestCase subclass.
static TestResult run(Test test)
          Runs a single test and collects its results.
static void runAndWait(Test suite)
          Runs a single test and waits until the user types RETURN.
 void setPrinter(ResultPrinter printer)
           
 TestResult start(String[] args)
          Starts a test run.
 void testEnded(String testName)
           
 void testFailed(int status, Test test, Throwable t)
           
 void testStarted(String testName)
           
 
Methods inherited from class junit.runner.BaseTestRunner
addError, addFailure, elapsedTimeAsString, endTest, extractClassName, getFilteredTrace, getFilteredTrace, getPreference, getPreference, getTest, savePreferences, setLoading, setPreference, startTest, truncate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUCCESS_EXIT

public static final int SUCCESS_EXIT
See Also:
Constant Field Values

FAILURE_EXIT

public static final int FAILURE_EXIT
See Also:
Constant Field Values

EXCEPTION_EXIT

public static final int EXCEPTION_EXIT
See Also:
Constant Field Values
Constructor Detail

TestRunner

public TestRunner()
Constructs a TestRunner.


TestRunner

public TestRunner(PrintStream writer)
Constructs a TestRunner using the given stream for all the output


TestRunner

public TestRunner(ResultPrinter printer)
Constructs a TestRunner using the given ResultPrinter all the output

Method Detail

run

public static void run(Class<? extends TestCase> testClass)
Runs a suite extracted from a TestCase subclass.


run

public static TestResult run(Test test)
Runs a single test and collects its results. This method can be used to start a test run from your program.
 public static void main (String[] args) {
    test.textui.TestRunner.run(suite());
 }
 


runAndWait

public static void runAndWait(Test suite)
Runs a single test and waits until the user types RETURN.


testFailed

public void testFailed(int status,
                       Test test,
                       Throwable t)
Specified by:
testFailed in class BaseTestRunner

testStarted

public void testStarted(String testName)
Specified by:
testStarted in class BaseTestRunner

testEnded

public void testEnded(String testName)
Specified by:
testEnded in class BaseTestRunner

doRun

public TestResult doRun(Test test)

doRun

public TestResult doRun(Test suite,
                        boolean wait)

main

public static void main(String[] args)

start

public TestResult start(String[] args)
                 throws Exception
Starts a test run. Analyzes the command line arguments and runs the given test suite.

Throws:
Exception

setPrinter

public void setPrinter(ResultPrinter printer)