Boost C++ Libraries

...one 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 a snapshot of the master branch, built from commit 6a5a04a711.
PrevUpHomeNext

Test suite entry/exit fixture

It is possible to define a test suite entry/exit fixture, so that the setup function is called only once upon entering the test suite, prior to running any of its test cases. Similarly the teardown function is also called only once upon the test suite exit, after all the enclosed test cases have been run. This is facilitated by the decorator fixture.

Example: Test suite entry/exit fixture

Code

#define BOOST_TEST_MODULE fixture_03
#include <boost/test/included/unit_test.hpp>
namespace utf = boost::unit_test;

struct F {
  F()  { BOOST_TEST_MESSAGE( "setup fixture" ); }
  ~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
};

BOOST_AUTO_TEST_SUITE(s, * utf::fixture<F>())

  BOOST_AUTO_TEST_CASE(test_case1)
  {
    BOOST_TEST_MESSAGE("running test_case1");
    BOOST_TEST(true);
  }

  BOOST_AUTO_TEST_CASE(test_case2)
  {
    BOOST_TEST_MESSAGE("running test_case2");
    BOOST_TEST(true);
  }

BOOST_AUTO_TEST_SUITE_END()

Output

> fixture_03 --log_level=message
Running 2 test cases...
setup fixture
running test_case1
running test_case2
teardown fixture

*** No errors detected

In case of this fixture type, however, it is not possible to access any members of the fixture object.

[Caution] Caution

This is not equivalent to using the method described here.


PrevUpHomeNext