Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Fixture models

Several fixture interfaces are supported by the Unit Test Framework. The choice of the interface depends mainly on the usage of the fixture.

Fixture class model

The Unit Test Framework defines the generic fixture class model as follows:

struct <fixture-name>{
  <fixture-name>();      // setup function
  ~<fixture-name>();     // teardown function

In other words a fixture is expected to be implemented as a class where the class constructor serves as a setup method and class destructor serves as teardown method. The Unit Test Framework opted to avoid explicit names in fixture interface for setup and teardown methods, since it is considered most natural in C++ for tasks similar to RAII and coincides with the pure C++ solution discussed above.

This model is expected from fixtures used with BOOST_FIXTURE_TEST_CASE and BOOST_FIXTURE_TEST_SUITE.

[Caution] Caution

The above interface prevents you from reporting errors in the teardown procedure using an exception. It does make sense though: if somehow more than one fixture is assigned to a test unit (e.g. using fixture decorator), you want all teardown procedures to run, even if some may experience problems.

Flexible models

In addition to BOOST_FIXTURE_TEST_CASE and BOOST_FIXTURE_TEST_SUITE the Unit Test Framework allows to associate fixture with test unit using the decorator fixture. This decorator supports additional models for declaring the setup and teardown:

For complete example of test module which uses these models please check decorator fixture.