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 .

Figure C-23. The class TestFixture


 class TestFixture 


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




Unit Test Frameworks
Unit Test Frameworks
ISBN: 0596006896
EAN: 2147483647
Year: 2006
Pages: 146
Authors: Paul Hamill

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net