Home > The Unit Test Framework > User's guide > Fixtures > Generic model
PrevNext

Generic fixture model

The UTF defines the generic fixture 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 UTF opted to avoid explicit names in fixture interface for setup and teardown methods, since is considered most natural in C++ for tasks similar to RAII and coincides with the pure C++ solution discusses earlier.

[Important] Important

The above interface prevents you to report 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, you want all teardown procedures to run, even if some may experience problems.


PrevUpHomeNext