Protocol and data driven testingThe TestSuite is used to implement protocol and data driven tests. More...

#include <cxxtools/unit/testsuite.h>

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

Classes

class  Context

Public Member Functions

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

Static Public Attributes

static TestProtocol defaultProtocol

Protected Member Functions

template<class ParentT >
void registerMethod (const std::string &name, ParentT &parent, void(ParentT::*method)())
template<class ParentT , typename A1 >
void registerMethod (const std::string &name, ParentT &parent, void(ParentT::*method)(A1))
template<class ParentT , typename A1 , typename A2 >
void registerMethod (const std::string &name, ParentT &parent, void(ParentT::*method)(A1, A2))
template<class ParentT , typename A1 , typename A2 , typename A3 >
void registerMethod (const std::string &name, ParentT &parent, void(ParentT::*method)(A1, A2, A3))
template<class ParentT , typename A1 , typename A2 , typename A3 , typename A4 >
void registerMethod (const std::string &name, ParentT &parent, void(ParentT::*method)(A1, A2, A3, A4))
template<class ParentT , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 >
void registerMethod (const std::string &name, ParentT &parent, void(ParentT::*method)(A1, A2, A3, A4, A5))
- 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

Protocol and data driven testing

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

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

Construct by name and protocol.

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.
cxxtools::unit::TestSuite::~TestSuite ( )

Member Function Documentation

template<class ParentT >
void cxxtools::unit::TestSuite::registerMethod ( const std::string &  name,
ParentT &  parent,
void(ParentT::*)()  method 
)
inlineprotected
template<class ParentT , typename A1 >
void cxxtools::unit::TestSuite::registerMethod ( const std::string &  name,
ParentT &  parent,
void(ParentT::*)(A1)  method 
)
inlineprotected
template<class ParentT , typename A1 , typename A2 >
void cxxtools::unit::TestSuite::registerMethod ( const std::string &  name,
ParentT &  parent,
void(ParentT::*)(A1, A2)  method 
)
inlineprotected
template<class ParentT , typename A1 , typename A2 , typename A3 >
void cxxtools::unit::TestSuite::registerMethod ( const std::string &  name,
ParentT &  parent,
void(ParentT::*)(A1, A2, A3)  method 
)
inlineprotected
template<class ParentT , typename A1 , typename A2 , typename A3 , typename A4 >
void cxxtools::unit::TestSuite::registerMethod ( const std::string &  name,
ParentT &  parent,
void(ParentT::*)(A1, A2, A3, A4)  method 
)
inlineprotected
template<class ParentT , typename A1 , typename A2 , typename A3 , typename A4 , typename A5 >
void cxxtools::unit::TestSuite::registerMethod ( const std::string &  name,
ParentT &  parent,
void(ParentT::*)(A1, A2, A3, A4, A5)  method 
)
inlineprotected
virtual void cxxtools::unit::TestSuite::run ( )
virtual

Runs the test suite.

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

Implements cxxtools::unit::Test.

void cxxtools::unit::TestSuite::runAll ( )
void cxxtools::unit::TestSuite::runTest ( const std::string &  name,
const SerializationInfo args = 0,
size_t  argCount = 0 
)

Runs a registered test.

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
virtual void cxxtools::unit::TestSuite::setParameter ( const std::string &  name,
const cxxtools::SerializationInfo value 
)
virtual

TODO: rename setParameter.

void cxxtools::unit::TestSuite::setProtocol ( TestProtocol protocol)

Sets the protocol.

Parameters
protocolProtocol for the test
virtual void cxxtools::unit::TestSuite::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::TestSuite::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 TestSuite::setUp.

Reimplemented from cxxtools::unit::TestFixture.

Member Data Documentation

TestProtocol cxxtools::unit::TestSuite::defaultProtocol
static

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