2 / Copyright (c) 2003 Boost.Test contributors
4 / Distributed under the Boost Software License, Version 1.0. (See accompanying
5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 [section:decorators Decorators]
10 "Decorator" is a uniform mechanism for updating various attributes of the automatically registered test units. These
11 attributes affect how the test tree is processed during the execution of the test module and include test unit
12 description, floating-point tolerance and the number of expected failures among others. They are listed in detail in
13 the following sections.
15 [h4 Test case decorators]
17 You can apply more than one decorator to the same test unit. A list of decorators is applied to a test case by specifying
18 it as the second argument to macro __BOOST_AUTO_TEST_CASE__ or the third argument to macro __BOOST_FIXTURE_TEST_CASE__.
20 [bt_example decorator_01..Test unit decorators..run]
22 Each decorator in the list is preceded by an asterisk (`*`); the subsequent syntax resembles a function call and is
23 specified in detail for each decorator. If there is more than one decorator in the list, they are concatenated with no
24 additional separator; each asterisk indicates the beginning of a decorator. In the above example, test case `test_case1`
25 has one associated ['decorator:] __decorator_label__. This means that when test units are filtered based on label, this
26 test case will match to label `"trivial"`. Test case `test_case2` has three associated decorators: two of type `label`
27 and one of type `description`.
29 [/ ############################]
30 [section Suite-level decorators]
32 Similarly to test case it is possible to apply list of decorators to test suite. It is done by specifying a list of
33 decorators as the second argument to the macro __BOOST_AUTO_TEST_SUITE__ or the third argument to the macro
34 __BOOST_FIXTURE_TEST_SUITE__.
36 [bt_example decorator_02..Test suite decorators..run]
38 How a test suite decorator affects the processing of the test units inside of it varies with the decorator
39 and is described for each decorator in subsequent sections. For instance, the function of the decorator in the above
40 example is that when tests are filtered by label `"trivial"`, every test unit in suite `suite1` will be run.
42 Similar to C++ namespace test suite can be closed and reopened within the same test file or span more than one file
43 and you are allowed to apply different decorators in each point, where test suite is opened. If this is the case,
44 the list of decorators applied to the test suite is the union of decorators specified in each place. Here an example.
46 [bt_example decorator_03..Decorators on multiple suite openings..run]
48 In the above example, the scope of test suite `suite1` is opened three times. This results in a test suite containing
49 three test cases and associated with two __decorator_label__ decorators. Therefore running tests by label `"trivial"` as
50 well as by label `"simple"` both result in executing all three test cases from the suite.
52 [caution The above syntax for decorators requires that the compiler supports variadic macros (added in C++11). If you
53 intend for your test program to also work for compilers without variadic macros, use explicit decorator syntax,
58 [/ ############################]
59 [section Explicit decorator declaration]
61 There is another way of associating a decorator set with test units. Macro __BOOST_TEST_DECORATOR__ indicates that its set
62 of decorators is to be applied to the test unit or /test case sequence/ that immediately follows the declaration.
64 [bt_example decorator_00..explicit decorator declaration..run]
66 In the above example a decorator is applied to a [link boost_test.tests_organization.test_cases.test_case_generation
67 data-driven test case]. Macro __BOOST_DATA_TEST_CASE__ cannot take the decorator set as one of its arguments, therefore
68 the explicit decorator declaration is used. Macro __BOOST_DATA_TEST_CASE__ generates a sequence of 4 test cases. The
69 decorator set is applied to each of them.
71 Another use case for the explicit decorator declaration is when you intend for your test program to compile also on
72 compilers without variadic macros. In this case it is recommended that you use the more verbose syntax. It is summarized
73 in the following table:
76 [[Test unit to register][Concise syntax][Universal syntax]]
78 BOOST_AUTO_TEST_CASE(test_case, *decor1() *decor2())
83 BOOST_TEST_DECORATOR(*decor1() *decor2())
84 BOOST_AUTO_TEST_CASE(test_case)
90 [[test case with fixture][```
91 BOOST_FIXTURE_TEST_CASE(test_case, Fx, *decor1() *decor2())
96 BOOST_TEST_DECORATOR(*decor1() *decor2())
97 BOOST_FIXTURE_TEST_CASE(test_case, Fx)
104 BOOST_AUTO_TEST_SUITE(test_suite, *decor1() *decor2())
108 BOOST_AUTO_TEST_SUITE_END()
110 BOOST_TEST_DECORATOR(*decor1() *decor2())
111 BOOST_AUTO_TEST_SUITE(test_suite)
115 BOOST_AUTO_TEST_SUITE_END()
118 [[test suite with fixture][```
119 BOOST_FIXTURE_TEST_SUITE(test_suite, Fx, *decor1() *decor2())
123 BOOST_AUTO_TEST_SUITE_END()
125 BOOST_TEST_DECORATOR(*decor1() *decor2())
126 BOOST_FIXTURE_TEST_SUITE(test_suite, Fx)
130 BOOST_AUTO_TEST_SUITE_END()
133 [[data-driven test case][```
136 BOOST_TEST_DECORATOR(*decor1() *decor2())
137 BOOST_DATA_TEST_CASE(test_case, data, var)
143 [[test case template][```
146 BOOST_TEST_DECORATOR(*decor1() *decor2())
147 BOOST_AUTO_TEST_CASE_TEMPLATE(test_case, T, type_list)
153 [[test case template with fixture][```
156 BOOST_TEST_DECORATOR(*decor1() *decor2())
157 BOOST_FIXTURE_TEST_CASE_TEMPLATE(test_case, T, type_list, Fx)
164 Throughout the reminder of this documentation we use only the concise syntax.
169 [endsect] [/ section decorators]