TestSuite Class Reference

#include <Pt/Unit/TestSuite.h>

Protocol and data driven testing. More...

Inherits Test, and TestFixture.

Public Member Functions

 TestSuite (const std::string &name, TestProtocol &protocol=TestSuite::defaultProtocol)
 Construct by name and protocol. More...
 ~TestSuite ()
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 ()
 Runs the test suite. More...
void runAll ()
 Runs all tests.
void runTest (const std::string &name, const SerializationInfo *args=0, std::size_t argCount=0)
 Runs a registered test. More...
void setParent (Test *test)
 Sets the parent test.
void setProtocol (TestProtocol *protocol)
 Sets the protocol.
virtual void setUp ()
 Set up conText before running a test. More...
virtual void tearDown ()
 Clean up after the test run. More...

Detailed Description

The TestSuite is used to implement protocol and data driven tests. It inherits its ability to register methods and properties from Reflectable. The implementor is supposed to write and register the required test methods on construction.

class MyTest : public TestSuite
: TestSuite("MyTest")
this->registerMethod("test1", *this, &MyTest::test1);
void test1();

Once the test is written it can be registered to an application by using the RegisterTest class template.

The default protocol will run each registered test method when the test is run. Before each test method setUp is called and tearDown after each test. The TestProtocol can be replaced with a customised one and reflection can be used to call any method multiple times with the required data.

Constructor & Destructor Documentation

TestSuite ( const std::string &  name,
TestProtocol protocol = TestSuite::defaultProtocol 

Constructs a TestCase with the passed name and optionally a custom protocol. The protocol is not owned by the TestSuite, but can be owned by the derived class.

nameName of the test
protocolProtocol for the test.

Member Function Documentation

virtual void setUp ( )

This function is called before each registered tester function is invoked. It is meant to initialize any required resources.

Reimplemented from TestFixture.

virtual void tearDown ( )

This function is called after each registered tester function is invoked. It is meant to remove any resources previously initialized in TestSuite::setUp.

Reimplemented from TestFixture.

virtual void run ( )

The TestProtocol assosiated with the test will be executed. The default protocol will simply call all registered tests.

Implements Test.

void runTest ( const std::string &  name,
const SerializationInfo args = 0,
std::size_t  argCount = 0 

A test method will be called by name and the given arguments are passe to it just like when the reflection API is used. The method 'setUp' will be called before, and the method tearDown after the test. Signals inherited from Unit::Test are sent appropriatly.

nameName of the method to be run
argsArguments to invoke the method
argCountNumber of arguments
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.