Name

TestFixture

Description

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.

The class TestFixture
Figure C-23. The class TestFixture

Declaration

class TestFixture

Constructors/Destructors

virtual ~TestFixture( )

A destructor.

Public Methods

virtual void setUp( ) {}

Initializes the fixture’s shared objects. The default implementation does nothing.

virtual void tearDown( ) {}

Cleans up the fixture’s shared objects. The default implementation does nothing.

Protected/Private Methods

None.

Attributes

None.

Get Unit Test Frameworks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.