How To Use
 All Modules Pages
#include "stdafx.h"
#include "../../TestToolBox.h"
namespace TTB = TestToolBox;
/// [example of a conditional test fixture]
class MyCondFixture : public TTB::ConditionalFixtureBase
{
public:
explicit MyCondFixture(std::string const& in_configFile = "Default")
: m_configFile(in_configFile)
{
// writes info to test protocol
TTB_INFO_S("Constructor MyFixture " << m_configFile);
// start up test environment, set needed state, ...
}
~MyCondFixture()
{
TTB_INFO_S("Destructor MyFixture " << m_configFile);
// tear doown test environment or reset state changes, ...
}
private:
std::string m_configFile;
// ... (other data needed within destructor)
};
/// [example of a conditional test fixture]
//-----------------------------------------------------------------------------
/// [using conditional test case fixtures]
TTB_BOOST_TEST_CASE(TestTopicA)
{
TTB_COND_FIXTURE(MyCondFixture); // -> create fixture on heap
// test instructions follow...
}}
TTB_BOOST_TEST_CASE(TestTopicB)
{
TTB_COND_FIXTURE(MyCondFixture); // no action!
}}
TTB_BOOST_TEST_CASE(TestTopicC)
{
TTB_COND_FIXTURE(MyCondFixture); // no action!
}}
TTB_BOOST_TEST_CASE(TestTopicD)
{
TTB_COND_FIXTURE_1(MyCondFixture, "FirstConfig");
// -> delete last fixture and create new fixture instance
}}
TTB_BOOST_TEST_CASE(TestTopicE)
{
TTB_COND_FIXTURE_1(MyCondFixture, "FirstConfig"); // no action
}}
/// [using conditional test case fixtures]
TTB_BOOST_TEST_CASE(TestTopicF)
{
// You can also change fixtures within a test case
TTB_COND_FIXTURE_1(MyCondFixture, "ConfigTwo");
TTB_COND_FIXTURE_1(MyCondFixture, "ConfigTwo"); // no action
TTB_COND_FIXTURE_1(MyCondFixture, "ConfigTwo"); // no action
TTB_COND_FIXTURE(MyCondFixture);
TTB_COND_FIXTURE_1(MyCondFixture, "FirstConfig");
}}
//-----------------------------------------------------------------------------
/// [boost test suite fixture]
// Possibility: formulate a test fixture which is only executed at the begin of the testsuite
class MyBoostTestSuiteFixture
{
public:
MyBoostTestSuiteFixture()
{
// The boost test suite fixture "MyBoostTestSuiteFixture" will be constructed each
// time a BOOST test case within the suite is executed.
// The following line will be called for each test case,
// BUT only for the first test case the test fixture "MyFixture" will be constructed!
TTB_COND_FIXTURE_1(MyCondFixture, "ConfigXY");
// You may add initializations which will execute before each test case
// ...
}
};
/// [boost test suite fixture]
/// [using boost test suite fixture]
BOOST_FIXTURE_TEST_SUITE(TestSuiteWithOneTimeInitialization, MyBoostTestSuiteFixture);
TTB_BOOST_TEST_CASE(TestCaseA) // -> creation of MyCondFixture
{
}}
TTB_BOOST_TEST_CASE(TestCaseB) // no action
{
}}
TTB_BOOST_TEST_CASE(TestCaseC) // no action
{
}}
BOOST_AUTO_TEST_SUITE_END();
/// [using boost test suite fixture]