Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / test / doc / html / boost_test / section_faq.html
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
164 # indicates the location of the boost installation tree.
165 # hard-coded for our simple example.
166 set(BOOST_INCLUDE_DIRS $boost_installation_prefix/include)
167
168 # creates the executable
169 add_executable(test_executable test_file.cpp)
170 # indicates the include paths
171 target_include_directories(test_executable PRIVATE ${BOOST_INCLUDE_DIRS})
172
173 # declares a test with our executable
174 add_test(NAME test1 COMMAND test_executable)
175 </pre>
176 <p>
177       We will now create the build directory for this project (separate directory),
178       configure and build the project, as follow:
179     </p>
180 <pre class="programlisting"><span class="special">&gt;</span> <span class="identifier">cd</span> $<span class="identifier">test_path</span>
181 <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>
182 <span class="special">&gt;</span> <span class="identifier">cd</span> <span class="identifier">build</span>
183 <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>
184 <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>
185 <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>
186 </pre>
187 <div class="calloutlist"><table border="0" summary="Callout list">
188 <tr>
189 <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>
190 <td valign="top" align="left"><p>
191           we create a directory dedicated to the build, to avoid any pollution of
192           the sources with the temporary build files
193         </p></td>
194 </tr>
195 <tr>
196 <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>
197 <td valign="top" align="left"><p>
198           configuration of the project
199         </p></td>
200 </tr>
201 <tr>
202 <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>
203 <td valign="top" align="left"><p>
204           this command builds the project, cmake drives a native tool that is configured
205           on the previous command line
206         </p></td>
207 </tr>
208 <tr>
209 <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>
210 <td valign="top" align="left"><p>
211           runs the tests declared in the project and prints a report
212         </p></td>
213 </tr>
214 </table></div>
215 <p>
216       In the case you are using the <a class="link" href="usage_variants.html#boost_test.usage_variants.shared_lib">shared
217       libraries</a> variant of <span class="emphasis"><em>Unit Test Framework</em></span>, some
218       modifications should be done in your CMakeLists.txt.
219     </p>
220 <pre class="programlisting">cmake_minimum_required(VERSION 2.8.11)
221 project(my_first_test)
222 enable_testing()
223
224 # replace XX with the version you have
225 set(Boost_ADDITIONAL_VERSIONS "1.XX" "1.XX.0")
226
227 # finds boost, triggers an error otherwise
228 find_package(Boost XX REQUIRED COMPONENTS unit_test_framework)
229
230 # creates the executable
231 add_executable(test_executable test_file.cpp)
232 # indicates the include paths
233 target_include_directories(test_executable PRIVATE ${Boost_INCLUDE_DIRS})
234 # indicates the shared library variant
235 target_compile_definitions(test_executable PRIVATE "BOOST_TEST_DYN_LINK=1")
236 # indicates the link paths
237 target_link_libraries(test_executable ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
238
239 # declares a test with our executable
240 add_test(NAME test1 COMMAND test_executable)
241
242 </pre>
243 <p>
244       We will now create the build directory for this project (separate directory),
245       configure and build the project, as follow:
246     </p>
247 <pre class="programlisting"><span class="special">&gt;</span> <span class="identifier">cd</span> $<span class="identifier">test_path</span>
248 <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>
249 <span class="special">&gt;</span> <span class="identifier">cd</span> <span class="identifier">build</span>
250 <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>
251 <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>
252 <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>
253 </pre>
254 <div class="calloutlist"><table border="0" summary="Callout list">
255 <tr>
256 <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>
257 <td valign="top" align="left"><p>
258           we create a directory dedicated to the build, to avoid any pollution of
259           the sources with the temporary build files
260         </p></td>
261 </tr>
262 <tr>
263 <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>
264 <td valign="top" align="left"><p>
265           configuration of the project, the <code class="computeroutput"><span class="identifier">BOOST_ROOT</span></code>
266           configuration element indicates the Boost module of <code class="computeroutput"><span class="identifier">cmake</span></code>
267           where to find our installation
268         </p></td>
269 </tr>
270 <tr>
271 <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>
272 <td valign="top" align="left"><p>
273           this command builds the project, cmake drives a native tool that is configured
274           on the previous command line
275         </p></td>
276 </tr>
277 <tr>
278 <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>
279 <td valign="top" align="left"><p>
280           runs the tests declared in the project and prints a report
281         </p></td>
282 </tr>
283 </table></div>
284 </div>
285 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
286 <td align="left"></td>
287 <td align="right"><div class="copyright-footer">Copyright &#169; 2001-2019 Boost.Test
288       contributors<p>
289         Distributed under the Boost Software License, Version 1.0. (See accompanying
290         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>)
291       </p>
292 </div></td>
293 </tr></table>
294 <hr>
295 <div class="spirit-nav">
296 <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>
297 </div>
298 </body>
299 </html>