You can perform test case setup and cleanup actions using setUp and tearDown functions. setUp and tearDown are called before and after each test case, respectively.
To perform setup or cleanup actions for the whole test suite (called before and after each test suite), define custom setup/cleanup functions and register them with the following macros:
CPPTEST_TEST_SUITE_SETUP(setup_function_name) CPPTEST_TEST_SUITE_TEARDOWN(cleanup_function_name)
The registration should be added within the test suite declaration section (before the first test case registration). For example:
class MyTestSuite : public CppTest_TestSuite { public: CPPTEST_TEST_SUITE(MyTestSuite); CPPTEST_TEST_SUITE_SETUP(myTestSuiteSetUp); CPPTEST_TEST_SUITE_TEARDOWN(myTestSuiteTearDown); CPPTEST_TEST(test1); CPPTEST_TEST(test2); CPPTEST_TEST_SUITE_END(); void setUp(); void tearDown(); static void myTestSuiteSetUp(); static void myTestSuiteTearDown(); void test1(); void test2(); }; void MyTestSuite::myTestSuiteSetUp() { // Test suite setup } void MyTestSuite::myTestSuiteTearDown() { // Test suite cleanup }