CppUnit project page | FAQ | CppUnit home page

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# TestResult Class Reference
[Tracking test execution]

Manages TestListener. More...

`#include <TestResult.h>`

Inheritance diagram for TestResult:

[legend]
Collaboration diagram for TestResult:

[legend]
List of all members.

## Public Member Functions
| TestResult (SynchronizationObject *syncObject=0)
| Construct a TestResult.
virtual | ~TestResult ()
| Destroys a test result.
virtual void | addListener (TestListener *listener)
virtual void | removeListener (TestListener *listener)
virtual void | reset ()
| Resets the stop flag.
virtual void | stop ()
| Stop testing.
virtual bool | shouldStop () const
| Returns whether testing should be stopped.
virtual void | startTest (Test *test)
| Informs TestListener that a test will be started.
virtual void | addError (Test *test, Exception *e)
| Adds an error to the list of errors. The passed in exception caused the error.
virtual void | addFailure (Test *test, Exception *e)
| Adds a failure to the list of failures. The passed in exception caused the failure.
virtual void | endTest (Test *test)
| Informs TestListener that a test was completed.
virtual void | startSuite (Test *test)
| Informs TestListener that a test suite will be started.
virtual void | endSuite (Test *test)
| Informs TestListener that a test suite was completed.
virtual void | runTest (Test *test)
| Run the specified test.
virtual bool | protect (const Functor &functor, Test *test, const std::string &shortDescription=std::string(""))
| Protects a call to the specified functor.
virtual void | pushProtector (Protector *protector)
| Adds the specified protector to the protector chain.
virtual void | popProtector ()
| Removes the last protector from the protector chain.
## Protected Types
typedef CppUnitDeque< TestListener * > | TestListeners
## Protected Member Functions
void | addFailure (const TestFailure &failure)
| Called to add a failure to the list of failures.
virtual void | startTestRun (Test *test)
virtual void | endTestRun (Test *test)
## Protected Attributes
TestListeners | m_listeners
ProtectorChain * | m_protectorChain
bool | m_stop
## Private Member Functions
| TestResult (const TestResult &other)
TestResult & | operator= (const TestResult &other)

## Detailed Description

Manages TestListener.

A single instance of this class is used when running the test. It is usually created by the test runner (TestRunner).

This class shouldn't have to be inherited from. Use a TestListener or one of its subclasses to be informed of the ongoing tests. Use a Outputter to receive a test summary once it has finished

TestResult supplies a template method 'setSynchronizationObject()' so that subclasses can provide mutual exclusion in the face of multiple threads. This can be useful when tests execute in one thread and they fill a subclass of TestResult which effects change in another thread. To have mutual exclusion, override setSynchronizationObject() and make sure that you create an instance of ExclusiveZone at the beginning of each method.

See also:
  Test, TestListener, TestResultCollector, Outputter.

## Member Typedef Documentation

typedef CppUnitDeque<TestListener *> TestResult::TestListeners`[protected]`

## Constructor & Destructor Documentation

CPPUNIT_NS_BEGIN TestResult::TestResult | ( | SynchronizationObject * | syncObject = `0` | ) |

Construct a TestResult.

TestResult::~TestResult | ( |  | ) | `[virtual]`

Destroys a test result.

TestResult::TestResult | ( | const TestResult & | other | ) | `[private]`

## Member Function Documentation

void TestResult::addListener | ( | TestListener * | listener | ) | `[virtual]`

void TestResult::removeListener | ( | TestListener * | listener | ) | `[virtual]`

void TestResult::reset | ( |  | ) | `[virtual]`

Resets the stop flag.

void TestResult::stop | ( |  | ) | `[virtual]`

Stop testing.

bool TestResult::shouldStop | ( |  | ) | const`[virtual]`

Returns whether testing should be stopped.

void TestResult::startTest | ( | Test * | test | ) | `[virtual]`

Informs TestListener that a test will be started.

Reimplemented in TextTestResult.

void TestResult::addError | ( | Test * | test,
|  | Exception * | e |
| ) |  |  | `[virtual]`

Adds an error to the list of errors. The passed in exception caused the error.

void TestResult::addFailure | ( | Test * | test,
|  | Exception * | e |
| ) |  |  | `[virtual]`

Adds a failure to the list of failures. The passed in exception caused the failure.

void TestResult::endTest | ( | Test * | test | ) | `[virtual]`

Informs TestListener that a test was completed.

void TestResult::startSuite | ( | Test * | test | ) | `[virtual]`

Informs TestListener that a test suite will be started.

void TestResult::endSuite | ( | Test * | test | ) | `[virtual]`

Informs TestListener that a test suite was completed.

void TestResult::runTest | ( | Test * | test | ) | `[virtual]`

Run the specified test.

Calls startTestRun(), test->run(this), and finally endTestRun().

bool TestResult::protect | ( | const Functor & | functor,
|  | Test * | test,
|  | const std::string & | shortDescription = `std::string("")` |
| ) |  |  | `[virtual]`

Protects a call to the specified functor.

See Protector to understand how protector works. A default protector is always present. It captures CppUnit::Exception, std::exception and any other exceptions, retrieving as much as possible information about the exception as possible.

Additional Protector can be added to the chain to support other exception types using pushProtector() and popProtector().

Parameters:

  | functor | Functor to call (typically a call to setUp(), runTest() or tearDown().
  | test | Test the functor is associated to (used for failure reporting).
  | shortDescription | Short description override for the failure message.

void TestResult::pushProtector | ( | Protector * | protector | ) | `[virtual]`

Adds the specified protector to the protector chain.

void TestResult::popProtector | ( |  | ) | `[virtual]`

Removes the last protector from the protector chain.

void TestResult::addFailure | ( | const TestFailure & | failure | ) | `[protected]`

Called to add a failure to the list of failures.

Reimplemented in TextTestResult.

void TestResult::startTestRun | ( | Test * | test | ) | `[protected, virtual]`

void TestResult::endTestRun | ( | Test * | test | ) | `[protected, virtual]`

TestResult& TestResult::operator= | ( | const TestResult & | other | ) | `[private]`

## Member Data Documentation

TestListeners TestResult::m_listeners`[protected]`

ProtectorChain* TestResult::m_protectorChain`[protected]`

bool TestResult::m_stop`[protected]`

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

- TestResult.h
- TestResult.cpp

| hosts this site. |  | Send comments to: CppUnit Developers