decorators.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Decorators</title>
  5. <link rel="stylesheet" href="../../boostbook.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
  7. <link rel="home" href="../../index.html" title="Boost.Test">
  8. <link rel="up" href="../tests_organization.html" title="Declaring and organizing tests">
  9. <link rel="prev" href="test_tree/test_tree_content.html" title="Test tree content">
  10. <link rel="next" href="decorators/suite_level_decorators.html" title="Suite-level decorators">
  11. </head>
  12. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  13. <table cellpadding="2" width="100%"><tr>
  14. <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
  15. <td align="center"><a href="../../../../../../index.html">Home</a></td>
  16. <td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
  17. <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
  18. <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
  19. <td align="center"><a href="../../../../../../more/index.htm">More</a></td>
  20. </tr></table>
  21. <hr>
  22. <div class="spirit-nav">
  23. <a accesskey="p" href="test_tree/test_tree_content.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tests_organization.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="decorators/suite_level_decorators.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h3 class="title">
  27. <a name="boost_test.tests_organization.decorators"></a><a class="link" href="decorators.html" title="Decorators">Decorators</a>
  28. </h3></div></div></div>
  29. <div class="toc"><dl class="toc">
  30. <dt><span class="section"><a href="decorators/suite_level_decorators.html">Suite-level
  31. decorators</a></span></dt>
  32. <dt><span class="section"><a href="decorators/explicit_decorator_declaration.html">Explicit
  33. decorator declaration</a></span></dt>
  34. </dl></div>
  35. <p>
  36. "Decorator" is a uniform mechanism for updating various attributes
  37. of the automatically registered test units. These attributes affect how the
  38. test tree is processed during the execution of the test module and include
  39. test unit description, floating-point tolerance and the number of expected
  40. failures among others. They are listed in detail in the following sections.
  41. </p>
  42. <h5>
  43. <a name="boost_test.tests_organization.decorators.h0"></a>
  44. <span class="phrase"><a name="boost_test.tests_organization.decorators.test_case_decorators"></a></span><a class="link" href="decorators.html#boost_test.tests_organization.decorators.test_case_decorators">Test
  45. case decorators</a>
  46. </h5>
  47. <p>
  48. You can apply more than one decorator to the same test unit. A list of decorators
  49. is applied to a test case by specifying it as the second argument to macro
  50. <a class="link" href="../utf_reference/test_org_reference/test_org_boost_auto_test_case.html" title="BOOST_AUTO_TEST_CASE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE</span></code></a> or the third
  51. argument to macro <a class="link" href="../utf_reference/test_org_reference/test_org_boost_test_case_fixture.html" title="BOOST_FIXTURE_TEST_CASE"><code class="computeroutput"><span class="identifier">BOOST_FIXTURE_TEST_CASE</span></code></a>.
  52. </p>
  53. <h6>
  54. <a name="boost_test.tests_organization.decorators.h1"></a>
  55. <span class="phrase"><a name="boost_test.tests_organization.decorators.example_descr"></a></span><a class="link" href="decorators.html#boost_test.tests_organization.decorators.example_descr">Example:
  56. Test unit decorators</a>
  57. </h6>
  58. <div class="informaltable"><table class="table">
  59. <colgroup><col></colgroup>
  60. <thead><tr><th>
  61. <p>
  62. Code
  63. </p>
  64. </th></tr></thead>
  65. <tbody><tr><td>
  66. <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">decorator_01</span>
  67. <span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  68. <span class="keyword">namespace</span> <span class="identifier">utf</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span>
  69. <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case1</span><span class="special">,</span> <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">label</span><span class="special">(</span><span class="string">"trivial"</span><span class="special">))</span>
  70. <span class="special">{</span>
  71. <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">true</span><span class="special">);</span>
  72. <span class="special">}</span>
  73. <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case2</span><span class="special">,</span>
  74. <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">label</span><span class="special">(</span><span class="string">"trivial"</span><span class="special">)</span>
  75. <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">label</span><span class="special">(</span><span class="string">"cmp"</span><span class="special">)</span>
  76. <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">description</span><span class="special">(</span><span class="string">"testing equality of ones"</span><span class="special">))</span>
  77. <span class="special">{</span>
  78. <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="number">1</span> <span class="special">==</span> <span class="number">1</span><span class="special">);</span>
  79. <span class="special">}</span>
  80. </pre>
  81. </td></tr></tbody>
  82. </table></div>
  83. <div class="informaltable"><table class="table">
  84. <colgroup><col></colgroup>
  85. <thead><tr><th>
  86. <p>
  87. Output
  88. </p>
  89. </th></tr></thead>
  90. <tbody><tr><td>
  91. <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">decorator_01</span> <span class="special">--</span><span class="identifier">run_test</span><span class="special">=</span><span class="error">@</span><span class="identifier">trivial</span>
  92. <span class="identifier">Running</span> <span class="number">2</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span>
  93. <span class="special">***</span> <span class="identifier">No</span> <span class="identifier">errors</span> <span class="identifier">detected</span>
  94. <span class="special">&gt;</span> <span class="identifier">decorator_01</span> <span class="special">--</span><span class="identifier">run_test</span><span class="special">=</span><span class="error">@</span><span class="identifier">cmp</span>
  95. <span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span>
  96. <span class="special">***</span> <span class="identifier">No</span> <span class="identifier">errors</span> <span class="identifier">detected</span>
  97. </pre>
  98. </td></tr></tbody>
  99. </table></div>
  100. <p>
  101. Each decorator in the list is preceded by an asterisk (<code class="computeroutput"><span class="special">*</span></code>);
  102. the subsequent syntax resembles a function call and is specified in detail
  103. for each decorator. If there is more than one decorator in the list, they
  104. are concatenated with no additional separator; each asterisk indicates the
  105. beginning of a decorator. In the above example, test case <code class="computeroutput"><span class="identifier">test_case1</span></code>
  106. has one associated <span class="emphasis"><em>decorator:</em></span> <a class="link" href="../utf_reference/test_org_reference/decorator_label.html" title="label (decorator)"><code class="computeroutput"><span class="identifier">label</span></code></a>. This means that when test
  107. units are filtered based on label, this test case will match to label <code class="computeroutput"><span class="string">"trivial"</span></code>. Test case <code class="computeroutput"><span class="identifier">test_case2</span></code> has three associated decorators:
  108. two of type <code class="computeroutput"><span class="identifier">label</span></code> and one
  109. of type <code class="computeroutput"><span class="identifier">description</span></code>.
  110. </p>
  111. </div>
  112. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  113. <td align="left"></td>
  114. <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2019 Boost.Test
  115. contributors<p>
  116. Distributed under the Boost Software License, Version 1.0. (See accompanying
  117. file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
  118. </p>
  119. </div></td>
  120. </tr></table>
  121. <hr>
  122. <div class="spirit-nav">
  123. <a accesskey="p" href="test_tree/test_tree_content.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tests_organization.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="decorators/suite_level_decorators.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
  124. </div>
  125. </body>
  126. </html>