Setup and Teardown

Every test group can have a setup and a teardown method. The setup method is called *before* each test and the teardown method is called *after* each test.

You can define setup and teardown like this:

TEST_GROUP(FooTestGroup)
{
   void setup()
   {
      // Init stuff
   }

   void teardown()
   {
      // Uninit stuff
   }
};

TEST(FooTestGroup, Foo)
{
   // Test FOO
}

TEST(FooTestGroup, MoreFoo)
{
   // Test more FOO
}

TEST_GROUP(BarTestGroup)
{
   void setup()
   {
      // Init Bar
   }
};

TEST(BarTestGroup, Bar)
{
   // Test Bar
}

The test execution of this will *likely* (no guarantee of order in CppUTest) be:

  • setup BarTestGroup
  • Bar
  • setup FooTestGroup
  • MoreFoo
  • teardown FooTestGroup
  • setup FooTestGroup
  • Foo
  • teardown FooTestGroup