Application Class Reference

#include <Pt/Unit/Application.h>

Run registered tests. More...

Inherits Test.

Public Member Functions

 Application ()
 Default Constructor.
virtual ~Application ()
void attachReporter (Reporter &r)
 Add reporter for test events. More...
void attachReporter (Reporter &r, const std::string &testname)
 Add reporter for test events. More...
unsigned errors () const
 Returns the number of errors which occured during a run.
TestfindTest (const std::string &testname)
 Find a test by name. More...
void registerTest (Test &test)
 Register a test. More...
void run (const std::string &testName)
 Run test by name. More...
virtual void run ()
 Run all tests. More...

Static Public Member Functions

static Applicationinstance ()
 Returns the instance.
static std::list< Test * > & tests ()
 Returns a list of all registered test TODO: find another way to query available tests. More...

Private Member Functions

void detachReporter (Reporter &r)
 Removes a reporter.
const std::string & name () const
 Returns the name of the test.
Testparent ()
 Returns the parent test.
const Testparent () const
 Returns the parent test.
void reportAssertion (const TestContext &ctx, const Assertion &ass)
 Assertion notification. More...
void reportError (const TestContext &ctx)
 Error notification. More...
void reportException (const TestContext &ctx, const std::exception &ex)
 Exception notification. More...
void reportFinish (const TestContext &ctx)
 Finished notification. More...
void reportMessage (const std::string &msg)
 Message notification. More...
void reportStart (const TestContext &ctx)
 Reports the start of a test.
void reportSuccess (const TestContext &ctx)
 Success notification. More...
void setParent (Test *test)
 Sets the parent test.

Detailed Description

The application class serves as an environment for a number of tests to be run. An application object is usually created in the main loop of a program and the return value of Unit::Application::run returned. A reporter can be set for the application to process test events. Reporters can be made to print information to the console or write XML logs. A typical example may look like this:

int main()

The TestMain.h include already defines a main loop with an application for the common use case.

Member Function Documentation

Test* findTest ( const std::string &  testname)

Returns a pointer to the found test or 0 if not found.

void attachReporter ( Reporter r)

Adds the reporter r to report test events.

void attachReporter ( Reporter r,
const std::string &  testname 

Adds the reporter r to report test events of the test name testname.

void run ( const std::string &  testName)

This method will run a previously registered test. Use the RegisterTest<T> template to register a test to the application.

testNamename of the test to be run
virtual void run ( )

This method will run all tests that have been registered previously. Use the RegisterTest<T> template to register a test to the application.

Implements Test.

void registerTest ( Test test)

Registers the test test to the application. The application will not own the test and the caller has to make sure it exists as long as the application object. Tests can be deregistered by calling deregisterTest.

static std::list<Test*>& tests ( )
Reference to the registered tests.