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 ()
 Destructor.
 
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...
 
virtual void run ()
 Runs the test suite. More...
 
void runTest (const std::string &name, const SerializationInfo *args=0, std::size_t argCount=0)
 Runs a registered test. More...
 
void runAll ()
 Runs all tests.
 
const std::string & name () const
 Returns the name of the test.
 
void reportStart (const TestContext &ctx)
 Reports the start of a test.
 
void reportFinish (const TestContext &ctx)
 Finished notification. More...
 
void reportSuccess (const TestContext &ctx)
 Success notification. More...
 
void reportAssertion (const TestContext &ctx, const Assertion &ass)
 Assertion notification. More...
 
void reportException (const TestContext &ctx, const std::exception &ex)
 Exception notification. More...
 
void reportError (const TestContext &ctx)
 Error notification. More...
 
void reportMessage (const std::string &msg)
 Message notification. More...
 
void setParent (Test *test)
 Sets the parent test.
 
Testparent ()
 Returns the parent test.
 
const Testparent () const
 Returns the parent test.
 
void attachReporter (Reporter &r)
 Add reporter for test events.
 
void detachReporter (Reporter &r)
 Removes a reporter.
 

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
{
public:
MyTest()
: 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()

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

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.

Parameters
nameName of the test
protocolProtocol for the test.

Member Function Documentation

◆ setUp()

virtual void setUp ( )
virtual

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

Reimplemented from TestFixture.

◆ tearDown()

virtual void tearDown ( )
virtual

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.

◆ run()

virtual void run ( )
virtual

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

Implements Test.

◆ runTest()

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.

Parameters
nameName of the method to be run
argsArguments to invoke the method
argCountNumber of arguments

◆ reportFinish()

void reportFinish ( const TestContext ctx)
inherited

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

◆ reportSuccess()

void reportSuccess ( const TestContext ctx)
inherited

This signal is sent when the test was successful.

◆ reportAssertion()

void reportAssertion ( const TestContext ctx,
const Assertion ass 
)
inherited

This signal is sent when a assertion failed.

◆ reportException()

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

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

◆ reportError()

void reportError ( const TestContext ctx)
inherited

This signal is sent when an unknown error occured.

◆ reportMessage()

void reportMessage ( const std::string &  msg)
inherited

This signal can be sent to report informational messages.

TestSuite(const std::string &name, TestProtocol &protocol=TestSuite::defaultProtocol)
Construct by name and protocol.