TestCase Class Referenceabstract

#include <Pt/Unit/TestCase.h>

Single test with setup and teardown. More...

Inherits Test, and TestFixture.

Public Member Functions

 TestCase (const std::string &name)
 Construct by name. More...
 
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 When the test is run, 'setUp' will be called first, then 'test' and finally 'tearDown'. Signals inherited from Unit::Test are sent appropriatly.
 
void setParent (Test *test)
 Sets the parent test.
 
virtual void setUp ()
 Set up conText before running a test. More...
 
virtual void tearDown ()
 Clean up after the test run. More...
 

Protected Member Functions

virtual void test ()=0
 Implements the actual test procedure When the test is run, this method will be called after setUp and before tearDown.
 

Detailed Description

A TestCase can be used for simple tests that require a initialization and deinitialization of resources. The implementor is supposed to implement the abstract method 'test' and the methods 'setUp' and 'tearDown' for resource management. When the test is run, 'setUp' will be called first, then 'test' and finally 'tearDown'.

class MyTest : public TestCase
{
public:
MyTest()
: TestCase("MyTest")
{}
virtual void setUp()
{
// init resource
}
virtual void tearDown()
{
// release resource
}
void test()
{
// test code using a resourc
}
};

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

Constructor & Destructor Documentation

TestCase ( const std::string &  name)

Constructs a TestCase with the passed name.

Parameters
nameName of the test

Member Function Documentation

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.

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 TestCase::setUp.

Reimplemented from TestFixture.

void reportFinish ( const TestContext ctx)
inherited

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

void reportSuccess ( const TestContext ctx)
inherited

This signal is sent when the test was successful.

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

This signal is sent when a assertion failed.

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

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

void reportError ( const TestContext ctx)
inherited

This signal is sent when an unknown error occured.

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

This signal can be sent to report informational messages.