testorg_reference.qbk 12 KB

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