section_faq.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Frequently Asked Questions</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="../index.html" title="Boost.Test">
  9. <link rel="prev" href="practical_usage_recommendations/web_wisdom.html" title="Web Wisdom">
  10. <link rel="next" href="section_glossary.html" title="Glossary">
  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/web_wisdom.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="section_glossary.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  27. <a name="boost_test.section_faq"></a><a class="link" href="section_faq.html" title="Frequently Asked Questions">Frequently Asked Questions</a>
  28. </h2></div></div></div>
  29. <h4>
  30. <a name="boost_test.section_faq.h0"></a>
  31. <span class="phrase"><a name="boost_test.section_faq.where_the_latest_version_of_the_"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.where_the_latest_version_of_the_">Where the
  32. latest version of the Boost Test Library is located?</a>
  33. </h4>
  34. <p>
  35. The latest version of Boost Test Library is available online at <a href="http://www.boost.org/libs/test" target="_top">http://www.boost.org/libs/test</a>.
  36. </p>
  37. <h4>
  38. <a name="boost_test.section_faq.h1"></a>
  39. <span class="phrase"><a name="boost_test.section_faq.i_found_a_bug_where_can_i_report"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.i_found_a_bug_where_can_i_report">I found a
  40. bug. Where can I report it?</a>
  41. </h4>
  42. <p>
  43. You can send a bug report to the boost users' mailing list and/or fill a ticket
  44. here <a href="https://svn.boost.org/trac/boost/" target="_top">https://svn.boost.org/trac/boost/</a>.
  45. </p>
  46. <h4>
  47. <a name="boost_test.section_faq.h2"></a>
  48. <span class="phrase"><a name="boost_test.section_faq.i_have_a_request_for_a_new_featu"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.i_have_a_request_for_a_new_featu">I have a
  49. request for a new feature. Where can I ask for it?</a>
  50. </h4>
  51. <p>
  52. You can send a request to the boost developers' mailing list and/or and/or
  53. fill a ticket here <a href="https://svn.boost.org/trac/boost/" target="_top">https://svn.boost.org/trac/boost/</a>.
  54. </p>
  55. <h4>
  56. <a name="boost_test.section_faq.h3"></a>
  57. <span class="phrase"><a name="boost_test.section_faq.how_to_create_test_case_using_th"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.how_to_create_test_case_using_th">How to create
  58. test case using the Unit Test Framework?</a>
  59. </h4>
  60. <p>
  61. To create a test case, use the macro
  62. </p>
  63. <pre class="programlisting"><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><span class="special">(</span> <span class="identifier">test_function</span> <span class="special">);</span>
  64. </pre>
  65. <p>
  66. For more details see the Unit Test Framework <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> documentation.
  67. </p>
  68. <h4>
  69. <a name="boost_test.section_faq.h4"></a>
  70. <span class="phrase"><a name="boost_test.section_faq.how_to_create_test_suite_using_t"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.how_to_create_test_suite_using_t">How to create
  71. test suite using the Unit Test Framework?</a>
  72. </h4>
  73. <p>
  74. To create a test suite use the macro
  75. </p>
  76. <pre class="programlisting"><a class="link" href="utf_reference/test_org_reference/test_org_boost_auto_test_suite.html" title="BOOST_AUTO_TEST_SUITE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_SUITE</span></code></a><span class="special">(</span> <span class="identifier">suite_name</span> <span class="special">);</span>
  77. </pre>
  78. <p>
  79. For more details see the Unit Test Framework <a class="link" href="utf_reference/test_org_reference/test_org_boost_auto_test_suite.html" title="BOOST_AUTO_TEST_SUITE"><code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_SUITE</span></code></a> documentation.
  80. </p>
  81. <h4>
  82. <a name="boost_test.section_faq.h5"></a>
  83. <span class="phrase"><a name="boost_test.section_faq.why_did_i_get_a_linker_error_whe"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.why_did_i_get_a_linker_error_whe">Why did I
  84. get a linker error when compiling my test program?</a>
  85. </h4>
  86. <p>
  87. Boost Test Library components provide several usage variants: to create a test
  88. program you can link with the one of the precompiled library variants or use
  89. header-only variant. For example, to use Unit Test Framework you may either
  90. include
  91. </p>
  92. <pre class="programlisting"><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">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
  93. </pre>
  94. <p>
  95. and link with
  96. </p>
  97. <pre class="programlisting"><span class="identifier">libunit_test_framework</span><span class="special">.</span><span class="identifier">lib</span></pre>
  98. <p>
  99. or you can include
  100. </p>
  101. <pre class="programlisting"><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>
  102. </pre>
  103. <p>
  104. in which case you should not need to link with any pre-compiled component.
  105. Note also that you should strictly follow specification on initialization function
  106. in other case some compilers may produce linker error like this.
  107. </p>
  108. <pre class="programlisting"><span class="identifier">Unresolved</span> <span class="identifier">external</span> <span class="identifier">init_unit_test_suite</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">**).</span>
  109. </pre>
  110. <p>
  111. The reason for this error is that in your implementation you should specify
  112. second argument of <code class="computeroutput"><span class="identifier">init_unit_test_suite</span></code>
  113. exactly as in the specification, i.e.: <code class="computeroutput"><span class="keyword">char</span><span class="special">*</span> <span class="special">[]</span></code>.
  114. </p>
  115. <h4>
  116. <a name="boost_test.section_faq.h6"></a>
  117. <span class="phrase"><a name="boost_test.section_faq.how_can_i_redirect_testing_outpu"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.how_can_i_redirect_testing_outpu">How can I
  118. redirect testing output?</a>
  119. </h4>
  120. <p>
  121. Use
  122. </p>
  123. <pre class="programlisting"><span class="identifier">unit_test_log</span><span class="special">::</span><span class="identifier">instance</span><span class="special">().</span><span class="identifier">set_log_output</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span> <span class="special">&amp;</span> <span class="special">)</span></pre>
  124. <p>
  125. For more details see the <span class="emphasis"><em>Unit Test Framework</em></span> <a class="link" href="testing_tools/output_stream_testing.html" title="Output streams testing tool">output
  126. test stream</a> documentation.
  127. </p>
  128. <h4>
  129. <a name="boost_test.section_faq.h7"></a>
  130. <span class="phrase"><a name="boost_test.section_faq.i_want_different_default_log_tra"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.i_want_different_default_log_tra">I want different
  131. default log trace level</a>
  132. </h4>
  133. <p>
  134. Use environment variable <a class="link" href="utf_reference/rt_param_reference/log_level.html" title="log_level"><code class="computeroutput"><span class="identifier">BOOST_TEST_LOG_LEVEL</span></code></a> to define desired
  135. log trace level. You still will be able to reset this value from the command
  136. line. For the list of acceptable values see the <span class="emphasis"><em>Unit Test Framework</em></span>
  137. <a class="link" href="runtime_config.html" title="Runtime parameters">runtime configuration</a> documentation.
  138. </p>
  139. <h4>
  140. <a name="boost_test.section_faq.h8"></a>
  141. <span class="phrase"><a name="boost_test.section_faq.is_there_dll_version_of_boost_te"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.is_there_dll_version_of_boost_te">Is there
  142. DLL version of Boost.Test components available on Win32 platform?</a>
  143. </h4>
  144. <p>
  145. Yes. Starting with Boost 1.34.0.
  146. </p>
  147. <h4>
  148. <a name="boost_test.section_faq.h9"></a>
  149. <span class="phrase"><a name="boost_test.section_faq.how_to_set_up_a_cmake_project_us"></a></span><a class="link" href="section_faq.html#boost_test.section_faq.how_to_set_up_a_cmake_project_us">How to set
  150. up a CMake project using <span class="emphasis"><em>Unit Test Framework</em></span> (extended)</a>
  151. </h4>
  152. <p>
  153. Suppose, you are building a test module from one translation unit <code class="computeroutput"><span class="identifier">test_file</span><span class="special">.</span><span class="identifier">cpp</span></code>. First, let's do it using the <a class="link" href="usage_variants.html#boost_test.usage_variants.single_header">header-only
  154. usage variant</a> of the <span class="emphasis"><em>Unit Test Framework</em></span>.
  155. </p>
  156. <p>
  157. Let's paste the following content in a <code class="computeroutput"><span class="identifier">CMakeLists</span><span class="special">.</span><span class="identifier">txt</span></code> at the
  158. same location than our test file <code class="computeroutput"><span class="identifier">test_file</span><span class="special">.</span><span class="identifier">cpp</span></code>:
  159. </p>
  160. <pre class="programlisting">cmake_minimum_required(VERSION 2.8.7)
  161. project(my_first_test)
  162. enable_testing()
  163. # indicates the location of the boost installation tree.
  164. # hard-coded for our simple example.
  165. set(BOOST_INCLUDE_DIRS $boost_installation_prefix/include)
  166. # creates the executable
  167. add_executable(test_executable test_file.cpp)
  168. # indicates the include paths
  169. target_include_directories(test_executable PRIVATE ${BOOST_INCLUDE_DIRS})
  170. # declares a test with our executable
  171. add_test(NAME test1 COMMAND test_executable)
  172. </pre>
  173. <p>
  174. We will now create the build directory for this project (separate directory),
  175. configure and build the project, as follow:
  176. </p>
  177. <pre class="programlisting"><span class="special">&gt;</span> <span class="identifier">cd</span> $<span class="identifier">test_path</span>
  178. <span class="special">&gt;</span> <span class="identifier">mkdir</span> <span class="identifier">build</span> <a class="co" name="boost_test.section_faq.c0" href="section_faq.html#boost_test.section_faq.c1"><img src="../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>
  179. <span class="special">&gt;</span> <span class="identifier">cd</span> <span class="identifier">build</span>
  180. <span class="special">&gt;</span> <span class="identifier">cmake</span> <span class="special">..</span> <a class="co" name="boost_test.section_faq.c2" href="section_faq.html#boost_test.section_faq.c3"><img src="../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a>
  181. <span class="special">&gt;</span> <span class="identifier">cmake</span> <span class="special">--</span><span class="identifier">build</span> <span class="special">.</span> <a class="co" name="boost_test.section_faq.c4" href="section_faq.html#boost_test.section_faq.c5"><img src="../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a>
  182. <span class="special">&gt;</span> <span class="identifier">ctest</span> <a class="co" name="boost_test.section_faq.c6" href="section_faq.html#boost_test.section_faq.c7"><img src="../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a>
  183. </pre>
  184. <div class="calloutlist"><table border="0" summary="Callout list">
  185. <tr>
  186. <td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c1"></a><a href="#boost_test.section_faq.c0"><img src="../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
  187. <td valign="top" align="left"><p>
  188. we create a directory dedicated to the build, to avoid any pollution of
  189. the sources with the temporary build files
  190. </p></td>
  191. </tr>
  192. <tr>
  193. <td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c3"></a><a href="#boost_test.section_faq.c2"><img src="../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
  194. <td valign="top" align="left"><p>
  195. configuration of the project
  196. </p></td>
  197. </tr>
  198. <tr>
  199. <td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c5"></a><a href="#boost_test.section_faq.c4"><img src="../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> </p></td>
  200. <td valign="top" align="left"><p>
  201. this command builds the project, cmake drives a native tool that is configured
  202. on the previous command line
  203. </p></td>
  204. </tr>
  205. <tr>
  206. <td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c7"></a><a href="#boost_test.section_faq.c6"><img src="../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a> </p></td>
  207. <td valign="top" align="left"><p>
  208. runs the tests declared in the project and prints a report
  209. </p></td>
  210. </tr>
  211. </table></div>
  212. <p>
  213. In the case you are using the <a class="link" href="usage_variants.html#boost_test.usage_variants.shared_lib">shared
  214. libraries</a> variant of <span class="emphasis"><em>Unit Test Framework</em></span>, some
  215. modifications should be done in your CMakeLists.txt.
  216. </p>
  217. <pre class="programlisting">cmake_minimum_required(VERSION 2.8.11)
  218. project(my_first_test)
  219. enable_testing()
  220. # replace XX with the version you have
  221. set(Boost_ADDITIONAL_VERSIONS "1.XX" "1.XX.0")
  222. # finds boost, triggers an error otherwise
  223. find_package(Boost XX REQUIRED COMPONENTS unit_test_framework)
  224. # creates the executable
  225. add_executable(test_executable test_file.cpp)
  226. # indicates the include paths
  227. target_include_directories(test_executable PRIVATE ${Boost_INCLUDE_DIRS})
  228. # indicates the shared library variant
  229. target_compile_definitions(test_executable PRIVATE "BOOST_TEST_DYN_LINK=1")
  230. # indicates the link paths
  231. target_link_libraries(test_executable ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
  232. # declares a test with our executable
  233. add_test(NAME test1 COMMAND test_executable)
  234. </pre>
  235. <p>
  236. We will now create the build directory for this project (separate directory),
  237. configure and build the project, as follow:
  238. </p>
  239. <pre class="programlisting"><span class="special">&gt;</span> <span class="identifier">cd</span> $<span class="identifier">test_path</span>
  240. <span class="special">&gt;</span> <span class="identifier">mkdir</span> <span class="identifier">build</span> <a class="co" name="boost_test.section_faq.c8" href="section_faq.html#boost_test.section_faq.c9"><img src="../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>
  241. <span class="special">&gt;</span> <span class="identifier">cd</span> <span class="identifier">build</span>
  242. <span class="special">&gt;</span> <span class="identifier">cmake</span> <span class="special">-</span><span class="identifier">DBOOST_ROOT</span><span class="special">=</span>$<span class="identifier">boost_installation_prefix</span> <span class="special">..</span> <a class="co" name="boost_test.section_faq.c10" href="section_faq.html#boost_test.section_faq.c11"><img src="../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a>
  243. <span class="special">&gt;</span> <span class="identifier">cmake</span> <span class="special">--</span><span class="identifier">build</span> <span class="special">.</span> <a class="co" name="boost_test.section_faq.c12" href="section_faq.html#boost_test.section_faq.c13"><img src="../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a>
  244. <span class="special">&gt;</span> <span class="identifier">ctest</span> <a class="co" name="boost_test.section_faq.c14" href="section_faq.html#boost_test.section_faq.c15"><img src="../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a>
  245. </pre>
  246. <div class="calloutlist"><table border="0" summary="Callout list">
  247. <tr>
  248. <td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c9"></a><a href="#boost_test.section_faq.c8"><img src="../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
  249. <td valign="top" align="left"><p>
  250. we create a directory dedicated to the build, to avoid any pollution of
  251. the sources with the temporary build files
  252. </p></td>
  253. </tr>
  254. <tr>
  255. <td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c11"></a><a href="#boost_test.section_faq.c10"><img src="../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
  256. <td valign="top" align="left"><p>
  257. configuration of the project, the <code class="computeroutput"><span class="identifier">BOOST_ROOT</span></code>
  258. configuration element indicates the Boost module of <code class="computeroutput"><span class="identifier">cmake</span></code>
  259. where to find our installation
  260. </p></td>
  261. </tr>
  262. <tr>
  263. <td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c13"></a><a href="#boost_test.section_faq.c12"><img src="../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> </p></td>
  264. <td valign="top" align="left"><p>
  265. this command builds the project, cmake drives a native tool that is configured
  266. on the previous command line
  267. </p></td>
  268. </tr>
  269. <tr>
  270. <td width="5%" valign="top" align="left"><p><a name="boost_test.section_faq.c15"></a><a href="#boost_test.section_faq.c14"><img src="../../../../../doc/src/images/callouts/4.png" alt="4" border="0"></a> </p></td>
  271. <td valign="top" align="left"><p>
  272. runs the tests declared in the project and prints a report
  273. </p></td>
  274. </tr>
  275. </table></div>
  276. </div>
  277. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  278. <td align="left"></td>
  279. <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2019 Boost.Test
  280. contributors<p>
  281. Distributed under the Boost Software License, Version 1.0. (See accompanying
  282. 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>)
  283. </p>
  284. </div></td>
  285. </tr></table>
  286. <hr>
  287. <div class="spirit-nav">
  288. <a accesskey="p" href="practical_usage_recommendations/web_wisdom.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="section_glossary.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  289. </div>
  290. </body>
  291. </html>