CppUnit project page | FAQ

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
TextTestRunner Class Reference
Writing test result | Executing test

A text mode test runner. More...

`#include <TextTestRunner.h>`

Inheritance diagram for TextTestRunner:
[legend]
Collaboration diagram for TextTestRunner:
[legend]

## Public Member Functions
| TextTestRunner (Outputter *outputter=NULL)
virtual | ~TextTestRunner ()
bool | run (std::string testPath="", bool doWait=false, bool doPrintResult=true, bool doPrintProgress=true)
void | setOutputter (Outputter *outputter)
TestResultCollector & | result () const
TestResult & | eventManager () const
virtual void | run (TestResult &controller, const std::string &testPath="")

## Protected Member Functions
virtual void | wait (bool doWait)
virtual void | printResult (bool doPrintResult)

## Private Member Functions
| TextTestRunner (const TextTestRunner &)
TextTestRunner & | operator= (const TextTestRunner &)

## Private Attributes
TestResultCollector * | m_result
TestResult * | m_eventManager
Outputter * | m_outputter

## Detailed Description

A text mode test runner.

The test runner manage the life cycle of the added tests.

The test runner can run only one of the added tests or all the tests.

TestRunner prints out a trace as the tests are executed followed by a summary at the end. The trace and summary print are optional.

Here is an example of use:

CppUnit::TextTestRunner runner;
runner.addTest( ExampleTestCase::suite() );
runner.run( "", true ); // Run all tests and wait

The trace is printed using a TextTestProgressListener. The summary is printed using a TextOutputter.

You can specify an alternate Outputter at construction or later with setOutputter().

After construction, you can register additional TestListener to eventManager(), for a custom progress trace, for example.

CppUnit::TextTestRunner runner;
runner.addTest( ExampleTestCase::suite() );
runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter(
&runner.result(),
std::cerr ) );
MyCustomProgressTestListener progress;
runner.eventManager().addListener( &progress );
runner.run( "", true ); // Run all tests and wait

See also
  CompilerOutputter, XmlOutputter, TextOutputter.

## Constructor & Destructor Documentation

## ◆ TextTestRunner() [1/2]

CPPUNIT_NS_BEGIN TextTestRunner::TextTestRunner | ( | Outputter * | outputter = `NULL` | ) |

Constructs a new text runner.

Parameters

  outputter | used to print text result. Owned by the runner.

## ◆ ~TextTestRunner()

TextTestRunner::~TextTestRunner | ( |  | ) |
| virtual

## ◆ TextTestRunner() [2/2]

TextTestRunner::TextTestRunner | ( | const TextTestRunner & |  | ) |
| private

## Member Function Documentation

## ◆ eventManager()

TestResult & TextTestRunner::eventManager | ( |  | ) | const

Returns the event manager. The instance of TestResult results returned is the one that is used to run the test. Use this to register additional TestListener before running the tests.

## ◆ operator=()

TextTestRunner& TextTestRunner::operator= | ( | const TextTestRunner & |  | ) |
| private

## ◆ printResult()

void TextTestRunner::printResult | ( | bool | doPrintResult | ) |
| protected virtual

## ◆ result()

TestResultCollector & TextTestRunner::result | ( |  | ) | const

Returns the result of the test run. Use this after calling run() to access the result of the test run.

## ◆ run() [1/2]

bool TextTestRunner::run | ( | std::string | testName = `""`,
|  | bool | doWait = `false`,
|  | bool | doPrintResult = `true`,
|  | bool | doPrintProgress = `true`
| ) |  |

Runs the named test case.

Parameters

  testName | Name of the test case to run. If an empty is given, then all added tests are run. The name can be the name of any test in the hierarchy.
  doWait | if `true` then the user must press the RETURN key before the run() method exit.
  doPrintResult | if `true` (default) then the test result are printed on the standard output.
  doPrintProgress | if `true` (default) then TextTestProgressListener is used to show the progress.

Returns
  `true` is the test was successful, `false` if the test failed or was not found.

## ◆ run() [2/2]

void TextTestRunner::run | ( | TestResult & | controller,
|  | const std::string & | testPath = `""`
| ) |  |
| virtual

## ◆ setOutputter()

void TextTestRunner::setOutputter | ( | Outputter * | outputter | ) |

Specifies an alternate outputter.

Notes that the outputter will be use after the test run only if printResult was `true`.

Parameters

  outputter | New outputter to use. The previous outputter is destroyed. The TextTestRunner assumes ownership of the outputter.

See also
  CompilerOutputter, XmlOutputter, TextOutputter.

## ◆ wait()

void TextTestRunner::wait | ( | bool | doWait | ) |
| protected virtual

## Member Data Documentation

## ◆ m_eventManager

TestResult* TextTestRunner::m_eventManager
| private

## ◆ m_outputter

Outputter* TextTestRunner::m_outputter
| private

## ◆ m_result

TestResultCollector* TextTestRunner::m_result
| private

The documentation for this class was generated from the following files:

- ui/text/TextTestRunner.h
- TextTestRunner.cpp

| Send comments to: CppUnit Developers