Next: , Previous: No Fork Mode, Up: Advanced Features



4.3 Test Fixtures

We may want multiple tests that all use the same Money. In such cases, rather than setting up and tearing down objects for each unit test, it may be convenient to add some setup that is constant across all the tests in a test case. In the Extreme Programming (XP) approach to unit tests, each such setup is called a test fixture.

A fixture is created by defining a setup and/or a teardown function, and associating it with a test case. There are two kinds of test fixtures in Check: checked and unchecked fixtures. These are defined as follows:

Checked fixtures
are run inside the address space created by the fork to create the unit test. Before each unit test in a test case, the setup() function is run, if defined. After each unit test, the teardown() function is run, if defined. Since they run inside the forked address space, if checked fixtures signal or otherwise fail, they will be caught and reported by the SRunner.
Unchecked fixtures
are run in the same address space as the test program. Therefore they may not signal or exit, but may use the fail functions. The unchecked setup(), if defined, is run before the test case is started. The unchecked teardown(), if defined, is run after the test case is done.