]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/ |
2 | / Copyright (c) 2003 Boost.Test contributors | |
3 | / | |
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) | |
6 | /] | |
7 | ||
8 | [section:test_org_reference Tests declaration and organization] | |
9 | ||
10 | ||
11 | ||
12 | ||
13 | [/ Test cases ###############################################################################################] | |
14 | [section:test_org_boost_test_case `BOOST_TEST_CASE`] | |
15 | Creates a test case for manual registration. The registration in the test tree should be performed manually. | |
16 | ||
17 | See [link ref_BOOST_TEST_CASE here] for more details. | |
18 | [endsect] [/section:test_org_boost_test_case] | |
19 | ||
20 | [section:test_org_boost_auto_test_case `BOOST_AUTO_TEST_CASE`] | |
21 | Declares and registers automatically a test case. | |
22 | ||
23 | See [link ref_BOOST_AUTO_TEST_CASE here] for more details. | |
24 | [endsect] [/section:test_org_boost_auto_test_case] | |
25 | ||
26 | ||
27 | [section:test_org_boost_test_case_auto_template `BOOST_AUTO_TEST_CASE_TEMPLATE`] | |
28 | Declares and registers automatically a typed test case. | |
29 | ||
30 | See [link ref_BOOST_AUTO_TEST_CASE_TEMPLATE here] for more details. | |
31 | [endsect] [/section:test_org_boost_test_case_auto_template] | |
32 | ||
33 | ||
34 | [section:test_org_boost_test_case_template `BOOST_TEST_CASE_TEMPLATE`] | |
35 | Creates a typed test case. The test case should have been declared with the macro __BOOST_TEST_CASE_TEMPLATE_FUNCTION__. | |
36 | The registration in the test tree should be performed manually. | |
37 | ||
38 | See [link ref_BOOST_TEST_CASE_TEMPLATE here] for more details. | |
39 | [endsect] [/section:test_org_boost_test_case_template] | |
40 | ||
41 | [section:test_org_boost_test_case_template_function `BOOST_TEST_CASE_TEMPLATE_FUNCTION`] | |
42 | Declares a typed test case. The registration in the test tree should be performed manually, using the macro | |
43 | __BOOST_TEST_CASE_TEMPLATE__. | |
44 | ||
45 | See [link ref_BOOST_TEST_CASE_TEMPLATE here] for more details. | |
46 | [endsect] [/section:test_org_boost_test_case_template_function] | |
47 | ||
48 | [section:test_org_boost_test_case_parameter `BOOST_PARAM_TEST_CASE`] | |
49 | Declares and registers automatically a test case with one parameter. | |
50 | ||
51 | See [link boost_test.tests_organization.test_cases.param_test here] for more details. | |
52 | [endsect] [/section:test_org_boost_test_case_parameter] | |
53 | ||
54 | ||
55 | [section:test_org_boost_test_dataset `BOOST_DATA_TEST_CASE`] | |
56 | Declares and registers a data-driven test case, using a particular dataset. | |
57 | ||
58 | Several forms of the macro are available. | |
59 | ||
60 | ||
61 | `` | |
62 | BOOST_DATA_TEST_CASE(test_case_name, dataset) | |
63 | { | |
64 | BOOST_TEST(sample != 0); | |
65 | } | |
66 | `` | |
67 | should be used for datasets with arity 1. In the body of the test case, the samples of the dataset are taken by the variable `sample`. | |
68 | ||
69 | `` | |
70 | BOOST_DATA_TEST_CASE(test_case_name, dataset, var1) | |
71 | { | |
72 | BOOST_TEST(var1 != 0); | |
73 | } | |
74 | `` | |
75 | same as the first form, but the samples are taken by the variable `var1` instead of the variable `sample` | |
76 | ||
77 | ||
78 | `` | |
79 | BOOST_DATA_TEST_CASE(test_case_name, dataset, var1, var2..., varN) | |
80 | { | |
81 | BOOST_TEST(var1 != 0); | |
82 | //... | |
83 | BOOST_TEST(varN != 0); | |
84 | } | |
85 | `` | |
86 | ||
87 | same as the second form, but for dataset of arity `N`. | |
88 | ||
89 | For compilers *lacking the variadic template* support, the maximal arity (the maximal value of `N`) is controlled by the macro | |
90 | `BOOST_TEST_DATASET_MAX_ARITY` which is set to `10` by default. If you need a greater value, define `BOOST_TEST_DATASET_MAX_ARITY` | |
91 | to the desired value *before* including the __UTF__ headers. | |
92 | ||
93 | See [link boost_test.tests_organization.test_cases.test_case_generation.datasets_auto_registration here] for more details. | |
94 | ||
95 | [endsect] [/section:test_org_boost_test_dataset] | |
96 | ||
97 | [section:test_org_boost_test_dataset_fixture `BOOST_DATA_TEST_CASE_F`] | |
98 | Declares and registers a data-driven test case, using a particular dataset and a fixture. This is basically the same as | |
99 | __BOOST_DATA_TEST_CASE__ with fixture support added. | |
100 | ||
101 | `` | |
102 | struct my_fixture { | |
103 | my_fixture() : some_string("environment X") { | |
104 | } | |
105 | std::string some_string; | |
106 | }; | |
107 | ||
108 | BOOST_DATA_TEST_CASE_F(my_fixture, test_case_name, dataset, var1, var2..., varN) | |
109 | { | |
110 | BOOST_TEST(var1 != 0); | |
111 | //... | |
112 | BOOST_TEST(varN != 0); | |
113 | } | |
114 | `` | |
115 | ||
116 | The fixture should implement the appropriate [link boost_test.tests_organization.fixtures.models interface]. | |
117 | As any fixture, it is possible to have test assertions in the fixture class. | |
118 | ||
119 | See [link boost_test.tests_organization.fixtures.case here] for more details on fixtures and | |
120 | [link boost_test.tests_organization.test_cases.test_case_generation.datasets_auto_registration here] for more details on datasets | |
121 | declaration. | |
122 | ||
123 | [endsect] [/section:test_org_boost_test_dataset_fixture] | |
124 | ||
125 | [/ Test suites ###############################################################################################] | |
126 | [section:test_org_boost_test_suite `BOOST_TEST_SUITE`] | |
127 | Creates a test suite. The created test suite should be added to the test tree manually. | |
128 | ||
129 | See [link ref_BOOST_TEST_SUITE here] for more details. | |
130 | [endsect] [/section:test_org_boost_test_suite] | |
131 | ||
132 | [section:test_org_boost_auto_test_suite `BOOST_AUTO_TEST_SUITE`] | |
133 | Indicates the beginning of a test suite. Test suites can be nested. | |
134 | ||
135 | See [link ref_BOOST_AUTO_TEST_SUITE here] for more details. | |
136 | [endsect] [/section:test_org_boost_auto_test_suite] | |
137 | ||
138 | [section:test_org_boost_auto_test_suite_end `BOOST_AUTO_TEST_SUITE_END`] | |
139 | Indicates the end of a test suite. Test suites can be nested. This macro should appear as many times as there is a | |
140 | __BOOST_AUTO_TEST_SUITE__. | |
141 | ||
142 | See [link ref_BOOST_AUTO_TEST_SUITE here] for more details. | |
143 | [endsect] [/section:test_org_boost_auto_test_suite_end] | |
144 | ||
145 | ||
146 | ||
147 | [/ Fixtures ###############################################################################################] | |
148 | [/-----------------------------------------------------------------] | |
149 | [section:test_org_boost_test_case_fixture `BOOST_FIXTURE_TEST_CASE`] | |
150 | Declares and registers a test case that uses a fixture. The class implementing the fixture should have the appropriate | |
151 | [link boost_test.tests_organization.fixtures.models interface]. | |
152 | As any fixture, it is possible to have test assertions in the fixture class. | |
153 | ||
154 | See [link boost_test.tests_organization.fixtures.case here] for more details. | |
155 | [endsect] [/section:test_org_boost_test_case_fixture] | |
156 | ||
157 | [/-----------------------------------------------------------------] | |
158 | [section:test_org_boost_test_suite_fixture `BOOST_FIXTURE_TEST_SUITE`] | |
159 | Declares and registers a fixture used by all test cases under a test suite. | |
160 | Each test case in the subtree of the test suite uses the fixture. | |
161 | The class implementing the fixture should have the appropriate [link boost_test.tests_organization.fixtures.models interface]. | |
162 | As any fixture, it is possible to have test assertions in the fixture class. | |
163 | ||
164 | See [link boost_test.tests_organization.fixtures.case here] for more details. | |
165 | [endsect] [/section:test_org_boost_test_case_fixture] | |
166 | ||
167 | [/-----------------------------------------------------------------] | |
168 | [section:test_org_boost_global_fixture `BOOST_GLOBAL_FIXTURE`] | |
169 | Declares and registers a global fixture. The global fixture is called before any of the test case in the test tree is executed. | |
170 | The class implementing the fixture should have the appropriate [link boost_test.tests_organization.fixtures.models interface]. | |
171 | As any fixture, it is possible to have test assertions in the global fixture. | |
172 | ||
173 | See [link boost_test.tests_organization.fixtures.global here] for more details. | |
174 | [endsect] [/section:test_org_boost_test_case_fixture] | |
175 | ||
176 | ||
177 | ||
178 | ||
179 | ||
180 | [/ Decorators ##############################################################################################] | |
181 | [section:test_org_boost_test_decorator `BOOST_TEST_DECORATOR`] | |
182 | Defines ['decorators] for a test unit. | |
183 | ||
184 | See [link boost_test.tests_organization.decorators here] for more details. | |
185 | [endsect] [/section:test_org_boost_test_decorator] | |
186 | ||
187 | ||
188 | [/-----------------------------------------------------------------] | |
189 | [section:decorator_depends_on depends_on (decorator)] | |
190 | ||
191 | `` | |
192 | depends_on(const_string dependent_test_name); | |
193 | `` | |
194 | ||
195 | Indicates a dependency from the decorated test unit (the child) to the designed test unit `dependent_test_name` (the parent). | |
196 | See [link boost_test.tests_organization.tests_dependencies here] for more details. | |
197 | ||
198 | [endsect] [/ section decorator_depends_on] | |
199 | ||
200 | ||
201 | ||
202 | [/-----------------------------------------------------------------] | |
203 | [section:decorator_description description (decorator)] | |
204 | ||
205 | `` | |
206 | description(const_string message); | |
207 | `` | |
208 | ||
209 | Attaches an arbitrary string to the test unit. | |
210 | See [link boost_test.tests_organization.semantic here] for more details. | |
211 | ||
212 | [endsect] [/ decorator description] | |
213 | ||
214 | ||
215 | ||
216 | ||
217 | [/-----------------------------------------------------------------] | |
218 | [section:decorator_enabled enabled / disabled (decorator)] | |
219 | ||
220 | `` | |
221 | enabled(); | |
222 | disabled(); | |
223 | `` | |
224 | ||
225 | Sets the test unit's __default_run_status__ to ['true] or ['false]. | |
226 | See [link boost_test.tests_organization.enabling here] for more details. | |
227 | ||
228 | [endsect] [/ section:decorator_enabled] | |
229 | ||
230 | ||
231 | [/-----------------------------------------------------------------] | |
232 | [section:decorator_enable_if enable_if (decorator)] | |
233 | ||
234 | `` | |
235 | template <bool Condition> enable_if(); | |
236 | `` | |
237 | Sets the test unit's __default_run_status__ to ['true] or ['false], depending on a compilation-time | |
238 | constant. | |
239 | See [link boost_test.tests_organization.enabling here] for more details. | |
240 | ||
241 | ||
242 | [endsect] [/ section enable_if] | |
243 | ||
244 | ||
245 | [/-----------------------------------------------------------------] | |
246 | [section:decorator_fixture fixture (decorator)] | |
247 | ||
248 | `` | |
249 | fixture(const boost::function<void()>& setup, const boost::function<void()>& teardown = {}); | |
250 | ||
251 | template <typename Fx> | |
252 | fixture<Fx>(); | |
253 | ||
254 | template <typename Fx, typename Arg> | |
255 | fixture<Fx>(const Arg& arg); | |
256 | `` | |
257 | ||
258 | Decorator `fixture` specifies a pair of functions (like `set_up` and `tear_down`) to be called before and after the | |
259 | corresponding test unit. At the suite level the `set_up` function is called once -- before the suite execution starts | |
260 | and `tear_down` function is called once -- after the suite execution ends. It comes in three forms. First expects two | |
261 | functions for set-up and tear-down (the second one can be skipped). The second expects a `DefaultConstructible` class. | |
262 | Its default constructor will be used as set-up function and its destructor as a tear-down function. Third requires a | |
263 | class with one-argument public constructor. Argument `arg` is forwarded to the constructor and this is the set-up | |
264 | function, its destructor is the tear-down function. There is no way to get access to the members of these fixtures from | |
265 | within the test case or test suite. | |
266 | ||
267 | [bt_example decorator_12..decorator fixture..run] | |
268 | ||
269 | For other ways of using fixtures, see [link boost_test.tests_organization.fixtures here]. | |
270 | ||
271 | [endsect] [/ section fixture] | |
272 | ||
273 | ||
274 | ||
275 | [/-----------------------------------------------------------------] | |
276 | [section:decorator_label label (decorator)] | |
277 | ||
278 | `` | |
279 | label(const_string label_name); | |
280 | `` | |
281 | ||
282 | Associates a test unit with label `label_name`. It is possible to associate more than one label with a test unit. | |
283 | See [link boost_test.tests_organization.tests_grouping here] for more details. | |
284 | ||
285 | [endsect] [/ section label] | |
286 | ||
287 | ||
288 | [/-----------------------------------------------------------------] | |
289 | [section:decorator_precondition precondition (decorator)] | |
290 | ||
291 | [def __class_assertion_result__ [classref boost::test_tools::assertion_result test_tools::assertion_result]] | |
292 | `` | |
293 | typedef boost::function<__class_assertion_result__ (test_unit_id)> predicate_t; | |
294 | ||
295 | precondition(predicate_t predicate); | |
296 | `` | |
297 | ||
298 | Associates a ['predicate] with a test unit that will determine its __default_run_status__ at run-time. | |
299 | See [link boost_test.tests_organization.enabling here] for more details. | |
300 | ||
301 | [endsect] [/ section decorator_precondition] | |
302 | [endsect] [/reference test organization] |