The larger a test module is and the more similar test cases are, the more likely it is to have test cases that require the same setup, cleanup, and maybe the same data. A component that contains these is called a test fixture or test context. Boost.Test provides several ways to define test fixtures for a test case, test suite, or a module (globally). In this recipe, we will look at how fixtures work.
The examples in this recipe use the following classes and functions for specifying test unit fixtures:
struct standard_fixture { standard_fixture() {BOOST_TEST_MESSAGE("setup");} ~standard_fixture() {BOOST_TEST_MESSAGE("cleanup");} int n {42}; }; struct extended_fixture { std::string name; int data; extended_fixture(std::string const & n = "") : name(n), data(0) { BOOST_TEST_MESSAGE("setup "+ name); } ~extended_fixture() { BOOST_TEST_MESSAGE("cleanup...