Test Class Referenceabstract

#include <Pt/Unit/Test.h>

Test base class More...

Inherits NonCopyable.

Inherited by Application [private], TestCase, TestMethod, and TestSuite.

Public Member Functions

virtual ~Test ()
 Destructor.
 
void attachReporter (Reporter &r)
 Add reporter for test events.
 
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...
 
virtual void run ()=0
 Runs the test. More...
 
void setParent (Test *test)
 Sets the parent test.
 

Protected Member Functions

 Test (const std::string &name)
 Construct a test by name. More...
 

Detailed Description

This is the base class for all types of tests that can be registered and run in a test application. It provides a virtual method run that is overriden by the derived classes and signals to inform about events that occur while the test is run.

Constructor & Destructor Documentation

Test ( const std::string &  name)
explicitprotected
Parameters
nameName of the test

Member Function Documentation

virtual void run ( )
pure virtual

Derived test classes are supposed to implement this method to run the test procedure. A derived class should send the 'started' signal at the begin of the test and send the 'finished' signal at the end of the test. If the test was successful, the 'success' signal is sent, otheriwse one of the signals indicating a failrue. In case of a failed assertion, the signal 'assertion' is sent, if a regular std::exception was the cause of the error the signal 'exception' is sent and and the signal 'error' indicates an unknown exception or error. This method should not propagate any exceptions

Implemented in TestSuite, Application, and TestCase.

void reportFinish ( const TestContext ctx)

This signal is sent when the test finished. It does not indicate that the test was successful.

void reportSuccess ( const TestContext ctx)

This signal is sent when the test was successful.

void reportAssertion ( const TestContext ctx,
const Assertion ass 
)

This signal is sent when a assertion failed.

void reportException ( const TestContext ctx,
const std::exception &  ex 
)

This signal is sent when a regular std::exception occured.

void reportError ( const TestContext ctx)

This signal is sent when an unknown error occured.

void reportMessage ( const std::string &  msg)

This signal can be sent to report informational messages.