⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
junit.textui

Class TestRunner

java.lang.Object
|
+--junit.runner.BaseTestRunner
   |
   +--junit.textui.TestRunner


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

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

createTestResult()

Creates the TestResult to be used for the test run.

TestResult

doRun(Test test)

TestResult

doRun(Test suite, boolean wait)

TestSuiteLoader

getLoader()

Always use the StandardTestSuiteLoader.

static void

main(String[] args)

void

pause(boolean wait)

static void

run(Class 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

runFailed(String message)

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)

Field Details

EXCEPTION_EXIT

public static final int EXCEPTION_EXIT


FAILURE_EXIT

public static final int FAILURE_EXIT


SUCCESS_EXIT

public static final int SUCCESS_EXIT

Constructor Details

TestRunner

public TestRunner()

Constructs a TestRunner.


TestRunner

public TestRunner(PrintStream writer)

Constructs a TestRunner using the given stream for all the output

Parameters:
writer

TestRunner

public TestRunner(ResultPrinter printer)

Constructs a TestRunner using the given ResultPrinter all the output

Parameters:
printer

Method Details

createTestResult

protected TestResult createTestResult()

Creates the TestResult to be used for the test run.


doRun

public TestResult doRun(Test test)

Parameters:
test

doRun

public TestResult doRun(Test suite, boolean wait)

Parameters:
suite
wait

getLoader

public TestSuiteLoader getLoader()

Always use the StandardTestSuiteLoader. Overridden from BaseTestRunner.


main

public static void main(String[] args)

Parameters:
args

pause

protected void pause(boolean wait)

Parameters:
wait

run

public static void run(Class testClass)

Runs a suite extracted from a TestCase subclass.

Parameters:
testClass

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());
 }

Parameters:
test

runAndWait

public static void runAndWait(Test suite)

Runs a single test and waits until the user types RETURN.

Parameters:
suite

runFailed

protected void runFailed(String message)

Parameters:
message

setPrinter

public void setPrinter(ResultPrinter printer)

Parameters:
printer

start

protected TestResult start(String[] args)

Starts a test run. Analyzes the command line arguments and runs the given test suite.

Parameters:
args

testEnded

public void testEnded(String testName)

Parameters:
testName

testFailed

public void testFailed(int status, Test test, Throwable t)

Parameters:
status
test
t

testStarted

public void testStarted(String testName)

Parameters:
testName