TestProtocol Class Reference

#include <Pt/Unit/TestProtocol.h>

Protocol for test suites. More...

Inherited by TextProtocol.

Public Member Functions

virtual ~TestProtocol ()
 Destructor.
 
virtual void run (TestSuite &test)
 Executes the protocol. More...
 

Detailed Description

This is the base class for protocols that can be used to run a test suite. The default implementation will simply run each registered test of the test suite without passing it any data. Implementors need to override the method TestProtocol::run to control the order and frequency of test method execution. This is useful to repeat tests, interleave them with waits, or implement stress-test patterns.

A protocol is assigned to a TestSuite through the constructor or via TestSuite::setProtocol().

class RetryProtocol : public Pt::Unit::TestProtocol
{
public:
void run(Pt::Unit::TestSuite& suite)
{
suite.runTest("Connect");
suite.runTest("Connect");
suite.runTest("Connect");
}
};

Test methods in a TestSuite can also take arguments for data-driven testing. The protocol calls TestSuite::runTest() with Pt::SerializationInfo objects to pass different data each time.

class MathProtocol : public Pt::Unit::TestProtocol
{
public:
void run(Pt::Unit::TestSuite& suite)
{
data[0] <<= 4;
data[1] <<= 9;
suite.runTest("MathTest::Addition", data, 2);
data[0] <<= 13;
data[1] <<= 2;
suite.runTest("MathTest::Addition", data, 2);
}
};

Member Function Documentation

◆ run()

virtual void run ( TestSuite test)
virtual

This method can be overriden to specify a custom protocol for a test suite. The default implementation will simply call each registered method of the test suite. Implementors will most likely call TestSuite::runTest to resolve a test method by name and pass it required arguments.

Parameters
testThe test suite to apply the protocol

Reimplemented in TextProtocol.

virtual void run(TestSuite &test)
Executes the protocol.
Protocol for test suites.
Definition: TestProtocol.h:93
Protocol and data driven testing.
Definition: TestSuite.h:84
void runTest(const std::string &name, const SerializationInfo *args=0, std::size_t argCount=0)
Runs a registered test.
Represents arbitrary types during serialization.
Definition: SerializationInfo.h:59