cxxtools::unit::Application Class Reference

Run registered tests. More...

#include <cxxtools/unit/application.h>

Inheritance diagram for cxxtools::unit::Application:
cxxtools::unit::Test cxxtools::Connectable cxxtools::NonCopyable

Public Member Functions

 Application ()
 Default Constructor.
virtual ~Application ()
 Destructor.
TestfindTest (const std::string &testname)
 Find a test by name.
void attachReporter (Reporter &r)
 Add reporter for test events.
void attachReporter (Reporter &r, const std::string &testname)
 Add reporter for test events.
void run (const std::string &testName)
 Run test by name.
virtual void run ()
 Run all tests.
unsigned errors () const
 Returns the number of errors which occured during a run.
void registerTest (Test &test)
 Register a test.
void deregisterTest (Test &test)
- Public Member Functions inherited from cxxtools::unit::Test
virtual ~Test ()
 Destructor.
const std::string & name () const
void reportStart (const TestContext &ctx)
 Reports the start of a test.
void reportFinish (const TestContext &ctx)
 Finished notification.
void reportSuccess (const TestContext &ctx)
 Success notification.
void reportAssertion (const TestContext &ctx, const Assertion &ass)
 Assertion notification.
void reportException (const TestContext &ctx, const std::exception &ex)
 Exception notification.
void reportError (const TestContext &ctx)
 Error notification.
void reportMessage (const std::string &msg)
 Message notification.
void setParent (Test *test)
Testparent ()
const Testparent () const
void detachReporter (Reporter &r)
- Public Member Functions inherited from cxxtools::Connectable
 Connectable ()
 Default constructor.
virtual ~Connectable ()
 Closes all connections.
virtual void onConnectionOpen (const Connection &c)
 Registers a Connection with the Connectable.
virtual void onConnectionClose (const Connection &c)
 Unregisters a Connection from the Connectable.
size_t connectionCount () const

Static Public Member Functions

static Applicationinstance ()
static std::list< Test * > & tests ()
 Returns a list of all registered test.
static void staticRegisterTest (Test &test)
 Register a test.

Additional Inherited Members

- Protected Member Functions inherited from cxxtools::unit::Test
 Test (const std::string &name)
 Construct a test by name.
- Protected Attributes inherited from cxxtools::Connectable
std::list< Connection_connections
 A list of all current connections.

Detailed Description

Run registered tests.

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()
{
cxxtools::Unit::Reporter reporter;
cxxtools::Unit::Application app;
app.setReporter(reporter);
return app.run();
}

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

Constructor & Destructor Documentation

cxxtools::unit::Application::Application ( )

Default Constructor.

virtual cxxtools::unit::Application::~Application ( )
virtual

Destructor.

Member Function Documentation

void cxxtools::unit::Application::attachReporter ( Reporter r)

Add reporter for test events.

Adds the reporter r to report test events.

Reimplemented from cxxtools::unit::Test.

void cxxtools::unit::Application::attachReporter ( Reporter r,
const std::string &  testname 
)

Add reporter for test events.

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

void cxxtools::unit::Application::deregisterTest ( Test test)
unsigned cxxtools::unit::Application::errors ( ) const
inline

Returns the number of errors which occured during a run.

Test* cxxtools::unit::Application::findTest ( const std::string &  testname)

Find a test by name.

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

static Application& cxxtools::unit::Application::instance ( )
static
void cxxtools::unit::Application::registerTest ( Test test)

Register a 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.

void cxxtools::unit::Application::run ( const std::string &  testName)

Run test by name.

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

Parameters
testNamename of the test to be run
virtual void cxxtools::unit::Application::run ( )
virtual

Run all tests.

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

Implements cxxtools::unit::Test.

static void cxxtools::unit::Application::staticRegisterTest ( Test test)
static

Register a 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*>& cxxtools::unit::Application::tests ( )
static

Returns a list of all registered test.

Returns
Reference to the registered tests.

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