The class TestFixture (see Figure C-23) defines the interface of a test fixture. TestCase is descended from TestFixture , so every test object is implicitly a test fixture. However, a test object is truly being used as a fixture only if it has multiple test methods that share objects. Philosophically, a fixture is a test environment, and the test methods interact with the environment to test different behaviors.
The TestFixture methods setUp() and tearDown( ) are used to initialize and clean up the fixture's shared objects. When there are multiple test methods in the fixture, setUp() and tearDown( ) are called for each one. This ensures test isolation by making sure the fixture is in the same state for each test.
TestFixture belongs to the namespace CppUnit . It is declared and implemented in TestFixture.h .
Initializes the fixture's shared objects. The default implementation does nothing.
Cleans up the fixture's shared objects. The default implementation does nothing.