Page tree

Skip to end of metadata
Go to start of metadata

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:


The registration should be added within the test suite declaration section (before the first test case registration). For example:

class MyTestSuite : public CppTest_TestSuite 
	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


  • Test suite setup/cleanup functions take no parameters.
  • We recommend using the static storage class specifier for C++ test suite setup/cleanup functions.
  • We do not recommend adding constructors/destructors to the test suite and attaching setup/teardown code to them because the test suite could be instantiated multiple times to run a subset of test cases each time—or even one per instance of the test suite. It is not correct to assume that the constructor is called only once before any test suite tests are executed, or that  the destructor is correspondingly called only after all tests have completed.
  • No labels