cxxtools::unit::TestCase Class Reference

Single test with setup and teardownA TestCase can be used for simple tests that require a initialization and deinitialization of resources. More...

#include <cxxtools/unit/testcase.h>

Inheritance diagram for cxxtools::unit::TestCase:
cxxtools::unit::Test cxxtools::unit::TestFixture cxxtools::Connectable cxxtools::NonCopyable

Classes

class  Context

Public Member Functions

 TestCase (const std::string &name)
 Construct by name.
virtual void run ()
 Runs the test When the test is run, 'setUp' will be called first, then 'test' and finally 'tearDown'.
virtual void setUp ()
 Set up conText before running a test.
virtual void tearDown ()
 Clean up after the test run.
- Public Member Functions inherited from cxxtools::unit::Test
virtual ~Test ()
 Destructor.
const std::string & name () const
void reportStart (const TestContext &ctx)
 Reports the start of a test.
void reportFinish (const TestContext &ctx)
 Finished notification.
void reportSuccess (const TestContext &ctx)
 Success notification.
void reportSkip (const TestContext &ctx)
 Skip notification.
void reportAssertion (const TestContext &ctx, const Assertion &ass)
 Assertion notification.
void reportException (const TestContext &ctx, const std::exception &ex)
 Exception notification.
void reportError (const TestContext &ctx)
 Error notification.
void reportMessage (const std::string &msg)
 Message notification.
void setParent (Test *test)
Testparent ()
const Testparent () const
void attachReporter (Reporter &r)
 Add reporter for test events.
void detachReporter (Reporter &r)
- Public Member Functions inherited from cxxtools::Connectable
 Connectable ()
 Default constructor.
virtual ~Connectable ()
 Closes all connections.
virtual void onConnectionOpen (const Connection &c)
 Registers a Connection with the Connectable.
virtual void onConnectionClose (const Connection &c)
 Unregisters a Connection from the Connectable.
size_t connectionCount () const
- Public Member Functions inherited from cxxtools::unit::TestFixture
virtual ~TestFixture ()

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.
- Protected Member Functions inherited from cxxtools::unit::Test
 Test (const std::string &name)
 Construct a test by name.
- Protected Member Functions inherited from cxxtools::Connectable
 Connectable (const Connectable &)
 Copy constructor.
Connectableoperator= (const Connectable &)
 Assignment operator.
const std::list< Connection > & connections () const
 Returns a list of all current connections.
std::list< Connection > & connections ()
 Returns a list of all current connections.
void clear ()
- Protected Member Functions inherited from cxxtools::NonCopyable
 NonCopyable ()

Additional Inherited Members

- Protected Attributes inherited from cxxtools::Connectable
std::list< Connection_connections
 A list of all current connections.

Detailed Description

Single test with setup and teardown

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

cxxtools::unit::TestCase::TestCase ( const std::string &  name)

Construct by name.

Constructs a TestCase with the passed name.

Parameters
nameName of the test

Member Function Documentation

virtual void cxxtools::unit::TestCase::run ( )
virtual

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.

Implements cxxtools::unit::Test.

virtual void cxxtools::unit::TestCase::setUp ( )
virtual

Set up conText before running a test.

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

Reimplemented from cxxtools::unit::TestFixture.

virtual void cxxtools::unit::TestCase::tearDown ( )
virtual

Clean up after the test run.

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 cxxtools::unit::TestFixture.

virtual void cxxtools::unit::TestCase::test ( )
protectedpure virtual

Implements the actual test procedure When the test is run, this method will be called after setUp and before tearDown.


The documentation for this class was generated from the following file: