...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
"Decorator" is a uniform mechanism for updating various attributes of the automatically registered test units. These attributes affect how the test tree is processed during the execution of the test module and include test unit description, floating-point tolerance and the number of expected failures among others. They are listed in detail in the following sections.
You can apply more than one decorator to the same test unit. A list of decorators
is applied to a test case by specifying it as the second argument to macro
BOOST_AUTO_TEST_CASE
or the third
argument to macro BOOST_FIXTURE_TEST_CASE
.
Code |
---|
#define BOOST_TEST_MODULE decorator_01 #include <boost/test/included/unit_test.hpp> namespace utf = boost::unit_test; BOOST_AUTO_TEST_CASE(test_case1, * utf::label("trivial")) { BOOST_TEST(true); } BOOST_AUTO_TEST_CASE(test_case2, * utf::label("trivial") * utf::label("cmp") * utf::description("testing equality of ones")) { BOOST_TEST(1 == 1); } |
Output |
---|
> decorator_01 --run_test=@trivial Running 2 test cases... *** No errors detected > decorator_01 --run_test=@cmp Running 1 test case... *** No errors detected |
Each decorator in the list is preceded by an asterisk (*
);
the subsequent syntax resembles a function call and is specified in detail
for each decorator. If there is more than one decorator in the list, they
are concatenated with no additional separator; each asterisk indicates the
beginning of a decorator. In the above example, test case test_case1
has one associated decorator: label
. This means that when test
units are filtered based on label, this test case will match to label "trivial"
. Test case test_case2
has three associated decorators:
two of type label
and one
of type description
.