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` and `BOOST_TEST_CASE_NAME`] 15Creates a test case for manual registration. The registration in the test tree should be performed manually. 16 17See [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`] 21Declares and registers automatically a test case. 22 23See [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`] 28Declares and registers automatically a typed test case. 29 30See [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`] 35Creates a typed test case. The test case should have been declared with the macro __BOOST_TEST_CASE_TEMPLATE_FUNCTION__. 36The registration in the test tree should be performed manually. 37 38See [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`] 42Declares a typed test case. The registration in the test tree should be performed manually, using the macro 43__BOOST_TEST_CASE_TEMPLATE__. 44 45See [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`] 49Declares and registers automatically a test case with one parameter. 50 51See [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`] 56Declares and registers a data-driven test case, using a particular dataset. 57 58Several forms of the macro are available. 59 60 61`` 62BOOST_DATA_TEST_CASE(test_case_name, dataset) 63{ 64 BOOST_TEST(sample != 0); 65} 66`` 67should 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`` 70BOOST_DATA_TEST_CASE(test_case_name, dataset, var1) 71{ 72 BOOST_TEST(var1 != 0); 73} 74`` 75same as the first form, but the samples are taken by the variable `var1` instead of the variable `sample` 76 77 78`` 79BOOST_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 87same as the second form, but for dataset of arity `N`. 88 89For 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` 91to the desired value *before* including the __UTF__ headers. 92 93See [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`] 98Declares 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`` 102struct my_fixture { 103 my_fixture() : some_string("environment X") { 104 } 105 std::string some_string; 106}; 107 108BOOST_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 116The fixture should implement the appropriate [link boost_test.tests_organization.fixtures.models interface]. 117As any fixture, it is possible to have test assertions in the fixture class. 118 119See [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 121declaration. 122 123[endsect] [/section:test_org_boost_test_dataset_fixture] 124 125[/ Test suites ###############################################################################################] 126[section:test_org_boost_test_suite `BOOST_TEST_SUITE`] 127Creates a test suite. The created test suite should be added to the test tree manually. 128 129See [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`] 133Indicates the beginning of a test suite. Test suites can be nested. 134 135See [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`] 139Indicates 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 142See [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`] 150Declares 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]. 152As any fixture, it is possible to have test assertions in the fixture class. 153 154See [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`] 159Declares and registers a fixture used by all test cases under a test suite. 160Each test case in the subtree of the test suite uses the fixture. 161The class implementing the fixture should have the appropriate [link boost_test.tests_organization.fixtures.models interface]. 162As any fixture, it is possible to have test assertions in the fixture class. 163 164See [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`] 169This macro is deprecated in favor of __BOOST_TEST_GLOBAL_FIXTURE__ and __BOOST_TEST_GLOBAL_CONFIGURATION__. 170[endsect] [/section:test_org_boost_test_case_fixture] 171 172[/-----------------------------------------------------------------] 173[section:test_org_boost_test_global_fixture `BOOST_TEST_GLOBAL_FIXTURE`] 174Declares and registers a global fixture. The global fixture acts exactly as a suite fixture attached to the 175[link boost_test.tests_organization.test_tree.master_test_suite master test suite], 176and is called before any of the test case in the test tree is executed. 177 178The class implementing the fixture should have the appropriate [link boost_test.tests_organization.fixtures.models interface]. 179As any fixture, it is possible to have test assertions in the global fixture. 180 181See [link boost_test.tests_organization.fixtures.global here] for more details. 182[endsect] [/section:test_org_boost_test_global_fixture] 183 184 185 186 187[/ Decorators ##############################################################################################] 188[section:test_org_boost_test_decorator `BOOST_TEST_DECORATOR`] 189Defines ['decorators] for a test unit. 190 191See [link boost_test.tests_organization.decorators here] for more details. 192[endsect] [/section:test_org_boost_test_decorator] 193 194 195[/-----------------------------------------------------------------] 196[section:decorator_depends_on depends_on (decorator)] 197 198`` 199depends_on(const_string dependent_test_name); 200`` 201 202Indicates a dependency from the decorated test unit (the child) to the designed test unit `dependent_test_name` (the parent). 203See [link boost_test.tests_organization.tests_dependencies here] for more details. 204 205[endsect] [/ section decorator_depends_on] 206 207 208 209[/-----------------------------------------------------------------] 210[section:decorator_description description (decorator)] 211 212`` 213description(const_string message); 214`` 215 216Attaches an arbitrary string to the test unit. 217See [link boost_test.tests_organization.semantic here] for more details. 218 219[endsect] [/ decorator description] 220 221 222 223 224[/-----------------------------------------------------------------] 225[section:decorator_enabled enabled / disabled (decorator)] 226 227`` 228enabled(); 229disabled(); 230`` 231 232Sets the test unit's __default_run_status__ to ['true] or ['false]. 233See [link boost_test.tests_organization.enabling here] for more details. 234 235[endsect] [/ section:decorator_enabled] 236 237 238[/-----------------------------------------------------------------] 239[section:decorator_enable_if enable_if (decorator)] 240 241`` 242template <bool Condition> enable_if(); 243`` 244Sets the test unit's __default_run_status__ to ['true] or ['false], depending on a compilation-time 245constant. 246See [link boost_test.tests_organization.enabling here] for more details. 247 248 249[endsect] [/ section enable_if] 250 251 252[/-----------------------------------------------------------------] 253[section:decorator_fixture fixture (decorator)] 254 255`` 256fixture(const boost::function<void()>& setup, const boost::function<void()>& teardown = {}); 257 258template <typename Fx> 259 fixture<Fx>(); 260 261template <typename Fx, typename Arg> 262 fixture<Fx>(const Arg& arg); 263`` 264 265Decorator `fixture` specifies a pair of functions (like `set_up` and `tear_down`) to be called before and after the 266corresponding test unit. At the suite level the `set_up` function is called once -- before the suite execution starts 267-- and `tear_down` function is called once -- after the suite execution ends. It comes in three forms. 268 269First expects two 270functions for set-up and tear-down (the second one can be skipped). 271 272The second expects a `DefaultConstructible` class. 273Its default constructor will be used as set-up function and its destructor as a tear-down function. 274 275The third form requires a 276class with one-argument public constructor. Argument `arg` is forwarded to the constructor. 277 278For the second and third form, the framework detects if there is a `setup` and/or `teardown` function implemented in the class, 279with the same declaration as described in the [link boost_test.tests_organization.fixtures.models fixture model]. 280If those member function are declared, they will be called right after construction and just 281before destruction respectively. 282 283[note There is no way to get access to the members of these fixtures from 284within the test case or test suite.] 285 286[bt_example decorator_12..decorator fixture..run] 287 288For other ways of using fixtures, see [link boost_test.tests_organization.fixtures here]. 289 290[endsect] [/ section fixture] 291 292 293 294[/-----------------------------------------------------------------] 295[section:decorator_label label (decorator)] 296 297`` 298label(const_string label_name); 299`` 300 301Associates a test unit with label `label_name`. It is possible to associate more than one label with a test unit. 302See [link boost_test.tests_organization.tests_grouping here] for more details. 303 304[endsect] [/ section label] 305 306 307[/-----------------------------------------------------------------] 308[section:decorator_precondition precondition (decorator)] 309 310[def __class_assertion_result__ [classref boost::test_tools::assertion_result test_tools::assertion_result]] 311`` 312typedef boost::function<__class_assertion_result__ (test_unit_id)> predicate_t; 313 314precondition(predicate_t predicate); 315`` 316 317Associates a ['predicate] with a test unit that will determine its __default_run_status__ at run-time. 318See [link boost_test.tests_organization.enabling here] for more details. 319 320[endsect] [/ section decorator_precondition] 321[endsect] [/reference test organization] 322