Previous: Test Fixture Examples, Up: Test Fixtures



4.3.2 Checked vs Unchecked Fixtures

Checked fixtures run once for each unit test in a test case, and so they should not be used for expensive setup. On the other hand, since unchecked fixtures may take down the entire test program, they should only be used if they are known to be safe. Recall that unchecked fixtures run once per test case, as opposed to once per unit test.

Additionally, checked and unchecked fixtures may behave differently in CK_NOFORK mode:

A checked fixture will generally not be affected by unit test side effects, since the setup() is run before each unit test. There is an exception for side effects to the total environment in which the test program lives: for example, if the setup() function initializes a file that a unit test then changes, the combination of the teardown() function and setup fuction must be able to restore the environment for the next unit test.

If the setup function in a fixture fails, in either checked or unchecked fixtures, the unit tests for the test case, and the teardown function for the fixture will not be run. A fixture error will be created and reported to the SRunner.