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 an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Explicit decorator declaration

There is another way of associating a decorator set with test units. Macro BOOST_TEST_DECORATOR indicates that its set of decorators is to be applied to the test unit or test case sequence that immediately follows the declaration.

Example: explicit decorator declaration

Code

#define BOOST_TEST_MODULE decorator_00
#include <boost/test/included/unit_test.hpp>
#include <boost/test/data/test_case.hpp>

namespace utf  = boost::unit_test;
namespace data = boost::unit_test::data;

BOOST_TEST_DECORATOR(* utf::description("with description"))
BOOST_DATA_TEST_CASE(test_1, data::xrange(4))
{
    BOOST_TEST(sample >= 0);
}

Output

> decorator_00 --list_content
test_1*: with description
test_1*: with description
test_1*: with description
test_1*: with description

In the above example a decorator is applied to a data-driven test case. Macro BOOST_DATA_TEST_CASE cannot take the decorator set as one of its arguments, therefore the explicit decorator declaration is used. Macro BOOST_DATA_TEST_CASE generates a sequence of 4 test cases. The decorator set is applied to each of them.

Another use case for the explicit decorator declaration is when you intend for your test program to compile also on compilers without variadic macros. In this case it is recommended that you use the more verbose syntax. It is summarized in the following table:

Test unit to register

Concise syntax

Universal syntax

test case

BOOST_AUTO_TEST_CASE(test_case, *decor1() *decor2())
{
  // assertions
}
BOOST_TEST_DECORATOR(*decor1() *decor2())
BOOST_AUTO_TEST_CASE(test_case)
{
  // assertions
}

test case with fixture

BOOST_FIXTURE_TEST_CASE(test_case, Fx, *decor1() *decor2())
{
  // assertions
}
BOOST_TEST_DECORATOR(*decor1() *decor2())
BOOST_FIXTURE_TEST_CASE(test_case, Fx)
{
  // assertions
}

test suite

BOOST_AUTO_TEST_SUITE(test_suite, *decor1() *decor2())

  // test units

BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_DECORATOR(*decor1() *decor2())
BOOST_AUTO_TEST_SUITE(test_suite)

  // test units

BOOST_AUTO_TEST_SUITE_END()

test suite with fixture

BOOST_FIXTURE_TEST_SUITE(test_suite, Fx, *decor1() *decor2())

  // test units

BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_DECORATOR(*decor1() *decor2())
BOOST_FIXTURE_TEST_SUITE(test_suite, Fx)

  // test units

BOOST_AUTO_TEST_SUITE_END()

data-driven test case

// not doable
BOOST_TEST_DECORATOR(*decor1() *decor2())
BOOST_DATA_TEST_CASE(test_case, data, var)
{
  // assertions
}

test case template

// not doable
BOOST_TEST_DECORATOR(*decor1() *decor2())
BOOST_AUTO_TEST_CASE_TEMPLATE(test_case, T, type_list)
{
  // assertions
}

test case template with fixture

// not doable
BOOST_TEST_DECORATOR(*decor1() *decor2())
BOOST_FIXTURE_TEST_CASE_TEMPLATE(test_case, T, type_list, Fx)
{
  // assertions
}

Throughout the reminder of this documentation we use only the concise syntax.


PrevUpHomeNext