general.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>General</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="../practical_usage_recommendations.html" title="Practical usage recommendations">
  9. <link rel="prev" href="../practical_usage_recommendations.html" title="Practical usage recommendations">
  10. <link rel="next" href="ide_usage_recommendations.html" title="IDE usage recommendations">
  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="../practical_usage_recommendations.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../practical_usage_recommendations.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="ide_usage_recommendations.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.practical_usage_recommendations.general"></a><a class="link" href="general.html" title="General">General</a>
  28. </h3></div></div></div>
  29. <h5>
  30. <a name="boost_test.practical_usage_recommendations.general.h0"></a>
  31. <span class="phrase"><a name="boost_test.practical_usage_recommendations.general.prefer_offline_compiled_librarie"></a></span><a class="link" href="general.html#boost_test.practical_usage_recommendations.general.prefer_offline_compiled_librarie">Prefer
  32. offline compiled libraries to the inline included components</a>
  33. </h5>
  34. <p>
  35. If you are just want to write quick simple test in environment where you
  36. never used Boost.Test before - yes, use included components. But if you plan
  37. to use Boost.Test on permanent basis, small investment of time needed to
  38. build (if not build yet), install and change you makefiles/project settings
  39. will soon return to you in a form of shorter compilation time. Why do you
  40. need to make your compiler do the same work over and over again?
  41. </p>
  42. <h5>
  43. <a name="boost_test.practical_usage_recommendations.general.h1"></a>
  44. <span class="phrase"><a name="boost_test.practical_usage_recommendations.general.if_you_use_only_free_function_ba"></a></span><a class="link" href="general.html#boost_test.practical_usage_recommendations.general.if_you_use_only_free_function_ba">If
  45. you use only free function based test cases advance to the automatic registration
  46. facility</a>
  47. </h5>
  48. <p>
  49. It's really easy to switch to automatic registration. And you don't need
  50. to worry about forgotten test cases.
  51. </p>
  52. <h5>
  53. <a name="boost_test.practical_usage_recommendations.general.h2"></a>
  54. <span class="phrase"><a name="boost_test.practical_usage_recommendations.general.to_find_location_of_first_error_"></a></span><a class="link" href="general.html#boost_test.practical_usage_recommendations.general.to_find_location_of_first_error_">To
  55. find location of first error reported by test tool within reused template
  56. function, use special hook within framework headers</a>
  57. </h5>
  58. <p>
  59. In some cases you are reusing the same template based code from within one
  60. test case (actually we recommend better solution in such case - see below).
  61. Now if an error gets reported by the test tool within that reused code you
  62. may have difficulty locating were exactly error occurred. To address this
  63. issue you could either a add <a class="link" href="../utf_reference/testout_reference/test_output_macro_message.html" title="BOOST_TEST_MESSAGE"><code class="computeroutput"><span class="identifier">BOOST_TEST_MESSAGE</span></code></a> statements in
  64. templated code that log current type id of template parameters or you can
  65. use special hook located in <code class="computeroutput"><span class="identifier">unit_test_result</span><span class="special">.</span><span class="identifier">hpp</span></code> called
  66. <code class="computeroutput"><span class="identifier">first_failed_assertion</span><span class="special">()</span></code>.
  67. If you set a breakpoint right on the line where this function is defined
  68. you will be able to unroll the stack and see where error actually occurred.
  69. </p>
  70. <h5>
  71. <a name="boost_test.practical_usage_recommendations.general.h3"></a>
  72. <span class="phrase"><a name="boost_test.practical_usage_recommendations.general.to_test_reusable_template_base_c"></a></span><a class="link" href="general.html#boost_test.practical_usage_recommendations.general.to_test_reusable_template_base_c">To
  73. test reusable template base component with different template parameter use
  74. test case template facility</a>
  75. </h5>
  76. <p>
  77. If you writing unit test for generic reusable component you may have a need
  78. to test it against set of different template parameter types . Most probably
  79. you will end up with a code like this:
  80. </p>
  81. <pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">TestType</span><span class="special">&gt;</span>
  82. <span class="keyword">void</span> <span class="identifier">specific_type_test</span><span class="special">(</span> <span class="identifier">TestType</span><span class="special">*</span> <span class="special">=</span> <span class="number">0</span> <span class="special">)</span>
  83. <span class="special">{</span>
  84. <span class="identifier">MyComponent</span><span class="special">&lt;</span><span class="identifier">TestType</span><span class="special">&gt;</span> <span class="identifier">c</span><span class="special">;</span>
  85. <span class="comment">// ... here we perform actual testing</span>
  86. <span class="special">}</span>
  87. <span class="keyword">void</span> <span class="identifier">my_component_test</span><span class="special">()</span>
  88. <span class="special">{</span>
  89. <span class="identifier">specific_type_test</span><span class="special">(</span> <span class="special">(</span><span class="keyword">int</span><span class="special">*)</span><span class="number">0</span> <span class="special">);</span>
  90. <span class="identifier">specific_type_test</span><span class="special">(</span> <span class="special">(</span><span class="keyword">float</span><span class="special">*)</span><span class="number">0</span> <span class="special">);</span>
  91. <span class="identifier">specific_type_test</span><span class="special">(</span> <span class="special">(</span><span class="identifier">UDT</span><span class="special">*)</span><span class="number">0</span> <span class="special">);</span>
  92. <span class="comment">// ...</span>
  93. <span class="special">}</span>
  94. </pre>
  95. <p>
  96. This is namely the situation where you would use test case template facility.
  97. It not only simplifies this kind of unit testing by automating some of the
  98. work, in addition every argument type gets tested separately under unit test
  99. monitor. As a result if one of types produce exception or non-fatal error
  100. you may still continue and get results from testing with other types.
  101. </p>
  102. </div>
  103. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  104. <td align="left"></td>
  105. <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2019 Boost.Test
  106. contributors<p>
  107. Distributed under the Boost Software License, Version 1.0. (See accompanying
  108. 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>)
  109. </p>
  110. </div></td>
  111. </tr></table>
  112. <hr>
  113. <div class="spirit-nav">
  114. <a accesskey="p" href="../practical_usage_recommendations.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../practical_usage_recommendations.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="ide_usage_recommendations.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
  115. </div>
  116. </body>
  117. </html>