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...
 
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.
 
virtual void setUp ()
 Set up conText before running a test. More...
 
virtual void tearDown ()
 Clean up after the test run. More...
 
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.
 

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 Pt::Unit::TestCase
{
public:
MyTest()
: Pt::Unit::TestCase("MyTest")
{}
virtual void setUp()
{
// init resource
}
virtual void tearDown()
{
// release resource
}
void test()
{
// test code using a resource
}
};

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

Constructor & Destructor Documentation

◆ TestCase()

TestCase ( const std::string &  name)

Constructs a TestCase with the passed name.

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

Reimplemented from TestFixture.

◆ 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.

Core module.
Definition: Allocator.h:33
virtual void test()=0
Implements the actual test procedure When the test is run, this method will be called after setUp and...
Single test with setup and teardown.
Definition: TestCase.h:82
TestCase(const std::string &name)
Construct by name.
virtual void tearDown()
Clean up after the test run.
Registers tests to an application.
Definition: RegisterTest.h:59
virtual void setUp()
Set up conText before running a test.