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 class model above has some limitations though:

This is why the Unit Test Framework also supports (Boost 1.65 on) optional setup and/or teardown functions as follow:

struct <fixture-name>{
  <fixture-name>();      // ctor
  ~<fixture-name>();     // dtor
  void setup();          // setup, optional
  void teardown();       // teardown, optional
[Note] Note

As mentioned, the declaration/implementation of the setup and teardown are optional: the Unit Test Framework will check the existence of those and will call them adequately. However in C++98, it is not possible to detect those declaration in case those are inherited (it works fine for compiler supporting auto and decltype).

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

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.