123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
- <title>Usage variants</title>
- <link rel="stylesheet" href="../boostbook.css" type="text/css">
- <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
- <link rel="home" href="../index.html" title="Boost.Test">
- <link rel="up" href="../index.html" title="Boost.Test">
- <link rel="prev" href="intro/how_to_read.html" title="How to read this documentation">
- <link rel="next" href="tests_organization.html" title="Declaring and organizing tests">
- </head>
- <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <table cellpadding="2" width="100%"><tr>
- <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
- <td align="center"><a href="../../../../../index.html">Home</a></td>
- <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
- <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
- <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
- <td align="center"><a href="../../../../../more/index.htm">More</a></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <a accesskey="p" href="intro/how_to_read.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="tests_organization.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
- </div>
- <div class="section">
- <div class="titlepage"><div><div><h2 class="title" style="clear: both">
- <a name="boost_test.usage_variants"></a><a class="link" href="usage_variants.html" title="Usage variants">Usage variants</a>
- </h2></div></div></div>
- <p>
- The <span class="emphasis"><em>Unit Test Framework</em></span> supports three different usage
- variants:
- </p>
- <div class="orderedlist"><ol class="orderedlist" type="1">
- <li class="listitem">
- <a class="link" href="usage_variants.html#boost_test.usage_variants.single_header">The header-only
- variant</a>
- </li>
- <li class="listitem">
- <a class="link" href="usage_variants.html#boost_test.usage_variants.static_lib">The static library
- variant</a>
- </li>
- <li class="listitem">
- <a class="link" href="usage_variants.html#boost_test.usage_variants.shared_lib">The shared library
- variant</a>
- </li>
- </ol></div>
- <p>
- In most cases you shouldn't have problems deciding which one to use, since
- there are clear reasons why would you prefer each one. Following sections should
- help you with the decision.
- </p>
- <h4>
- <a name="boost_test.usage_variants.h0"></a>
- <span class="phrase"><a name="boost_test.usage_variants.single_header"></a></span><a class="link" href="usage_variants.html#boost_test.usage_variants.single_header">Header-only
- usage variant</a>
- </h4>
- <p>
- If you prefer to avoid the compilation of standalone library, you should use
- the header-only variant of the <span class="emphasis"><em>Unit Test Framework</em></span>. This
- variant only requires you to include the unique header: <code class="computeroutput"><span class="preprocessor">#include</span>
- <span class="special"><</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">></span></code> and
- there is no need to link with any library. There are several ways to perform
- the initialization, but the simplest way is the following:
- </p>
- <pre class="programlisting"><span class="preprocessor">#define</span> <a class="link" href="utf_reference/link_references/link_boost_test_module_macro.html" title="BOOST_TEST_MODULE"><code class="computeroutput"><span class="identifier">BOOST_TEST_MODULE</span></code></a> <span class="identifier">test</span> <span class="identifier">module</span> <span class="identifier">name</span>
- <span class="preprocessor">#include</span> <span class="special"><</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">></span>
- </pre>
- <p>
- <a class="link" href="utf_reference/link_references/link_boost_test_module_macro.html" title="BOOST_TEST_MODULE"><code class="computeroutput"><span class="identifier">BOOST_TEST_MODULE</span></code></a> macro needs to be
- defined <span class="bold"><strong>before</strong></span> the include and should indicate
- the name of the test module. This name can include spaces and does not need
- to be wrapped in quotes.
- </p>
- <p>
- <a class="link" href="adv_scenarios/single_header_customizations.html" title="Header-only variant customizations">This
- section</a> gives additional details on how to customize this usage variant.
- In particular, it is possible to have several compilation units with this variant,
- as explained in the section <a class="link" href="adv_scenarios/single_header_customizations/multiple_translation_units.html" title="Header-only with multiple translation units">Header-only
- with multiple translation units</a>.
- </p>
- <h4>
- <a name="boost_test.usage_variants.h1"></a>
- <span class="phrase"><a name="boost_test.usage_variants.static_lib"></a></span><a class="link" href="usage_variants.html#boost_test.usage_variants.static_lib">Static
- library usage variant</a>
- </h4>
- <p>
- For most users, who has an access to pre-built static library <a href="#ftn.boost_test.usage_variants.f0" class="footnote" name="boost_test.usage_variants.f0"><sup class="footnote">[1]</sup></a> of the <span class="emphasis"><em>Unit Test Framework</em></span> or can <a class="link" href="adv_scenarios/build_utf.html" title="Building the Unit Test Framework">build
- it</a> themselves, following usage can be most versatile and simple approach.
- This usage variant entails two steps.
- </p>
- <div class="orderedlist"><ol class="orderedlist" type="1">
- <li class="listitem">
- <p class="simpara">
- First, the following line needs to be added to all translation units in
- the test module:
- </p>
- <pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">></span>
- </pre>
- <p class="simpara">
- One and <span class="bold"><strong>only one</strong></span> translation unit should
- include following lines:
- </p>
- <pre class="programlisting"><span class="preprocessor">#define</span> <a class="link" href="utf_reference/link_references/link_boost_test_module_macro.html" title="BOOST_TEST_MODULE"><code class="computeroutput"><span class="identifier">BOOST_TEST_MODULE</span></code></a> <span class="identifier">test</span> <span class="identifier">module</span> <span class="identifier">name</span>
- <span class="preprocessor">#include</span> <span class="special"><</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">></span>
- </pre>
- <p class="simpara">
- <a class="link" href="utf_reference/link_references/link_boost_test_module_macro.html" title="BOOST_TEST_MODULE"><code class="computeroutput"><span class="identifier">BOOST_TEST_MODULE</span></code></a> macro needs
- to be defined <span class="bold"><strong>before</strong></span> the include and should
- indicate the name of the test module. This name can include spaces and
- does not need to be wrapped in quotes.
- </p>
- </li>
- <li class="listitem">
- The second step is to link with the <span class="emphasis"><em>Unit Test Framework</em></span>
- <span class="bold"><strong>static</strong></span> library.
- </li>
- </ol></div>
- <div class="note"><table border="0" summary="Note">
- <tr>
- <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
- <th align="left">Note</th>
- </tr>
- <tr><td align="left" valign="top"><p>
- Header <code class="computeroutput"><span class="special"><</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">></span></code>
- is an <span class="emphasis"><em>aggregate</em></span> header: it includes most of the other
- headers that contains the Unit Test Framework definitions.
- </p></td></tr>
- </table></div>
- <p>
- The flip side of this usage variant is that each test module following this
- usage variant is going to be statically linked with <span class="emphasis"><em>Unit Test Framework</em></span>,
- which might be something you want to avoid (to save space for example). For
- more information about these configuration options check <a class="link" href="adv_scenarios/static_lib_customizations.html" title="Static-library variant customizations">this
- section</a>.
- </p>
- <h4>
- <a name="boost_test.usage_variants.h2"></a>
- <span class="phrase"><a name="boost_test.usage_variants.shared_lib"></a></span><a class="link" href="usage_variants.html#boost_test.usage_variants.shared_lib">Shared
- library usage variant</a>
- </h4>
- <p>
- In the project with large number of test modules the static library variant
- of the <span class="emphasis"><em>Unit Test Framework</em></span> may cause you to waste a lot
- of disk space. The solution is to link test module dynamically with the <span class="emphasis"><em>Unit
- Test Framework</em></span> built as a shared library. This usage variant entails
- two steps.
- </p>
- <div class="orderedlist"><ol class="orderedlist" type="1">
- <li class="listitem">
- <p class="simpara">
- First you need to add following lines to all translation units in a test
- module:
- </p>
- <pre class="programlisting"><span class="preprocessor">#define</span> <a class="link" href="utf_reference/link_references/link_boost_test_dyn_link.html" title="BOOST_TEST_DYN_LINK"><code class="computeroutput"><span class="identifier">BOOST_TEST_DYN_LINK</span></code></a>
- <span class="preprocessor">#include</span> <span class="special"><</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">></span>
- </pre>
- <p class="simpara">
- and <span class="bold"><strong>only one</strong></span> translation unit should include
- following lines
- </p>
- <pre class="programlisting"><span class="preprocessor">#define</span> <a class="link" href="utf_reference/link_references/link_boost_test_module_macro.html" title="BOOST_TEST_MODULE"><code class="computeroutput"><span class="identifier">BOOST_TEST_MODULE</span></code></a> <span class="identifier">test</span> <span class="identifier">module</span> <span class="identifier">name</span>
- <span class="preprocessor">#define</span> <a class="link" href="utf_reference/link_references/link_boost_test_dyn_link.html" title="BOOST_TEST_DYN_LINK"><code class="computeroutput"><span class="identifier">BOOST_TEST_DYN_LINK</span></code></a>
- <span class="preprocessor">#include</span> <span class="special"><</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">></span>
- </pre>
- <p class="simpara">
- <code class="computeroutput"><span class="identifier">BOOST_TEST_MODULE</span></code> and
- <code class="computeroutput"><span class="identifier">BOOST_TEST_DYN_LINK</span></code> macros
- needs to be defined <span class="bold"><strong>before</strong></span> the include.
- <code class="computeroutput"><span class="identifier">BOOST_TEST_MODULE</span></code> should
- be set to test module name. This name can include spaces and does not need
- to be wrapped in quotes.
- </p>
- </li>
- <li class="listitem">
- The second step is to link with the <span class="emphasis"><em>Unit Test Framework</em></span>
- <span class="bold"><strong>shared</strong></span> library.
- </li>
- </ol></div>
- <p>
- The flip side of this usage variant is that you will need to make sure the
- <span class="emphasis"><em>Unit Test Framework</em></span> shared library is accessible at runtime
- to a test module.
- </p>
- <p>
- In addition shared library usage variant facilitates custom test runners. For
- more information about this check <a class="link" href="adv_scenarios/shared_lib_customizations.html" title="Shared-library variant customizations">this
- section</a>.
- </p>
- <div class="caution"><table border="0" summary="Caution">
- <tr>
- <td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../doc/src/images/caution.png"></td>
- <th align="left">Caution</th>
- </tr>
- <tr><td align="left" valign="top"><p>
- On Windows, the test module and the <span class="emphasis"><em>Unit Test Framework</em></span>
- shared library should link to the same CRT. Not doing so (for instance <span class="emphasis"><em>Unit
- Test Framework</em></span> shared library in <span class="emphasis"><em>release</em></span>
- mode while the test module is in <span class="emphasis"><em>debug</em></span>) will lead to
- crashes.
- </p></td></tr>
- </table></div>
- <div class="footnotes">
- <br><hr style="width:100; text-align:left;margin-left: 0">
- <div id="ftn.boost_test.usage_variants.f0" class="footnote"><p><a href="#boost_test.usage_variants.f0" class="para"><sup class="para">[1] </sup></a>
- these files are distributed with the packaging systems on Linux and OSX for
- instance
- </p></div>
- </div>
- </div>
- <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
- <td align="left"></td>
- <td align="right"><div class="copyright-footer">Copyright © 2001-2019 Boost.Test
- contributors<p>
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- 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>)
- </p>
- </div></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <a accesskey="p" href="intro/how_to_read.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="tests_organization.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
- </div>
- </body>
- </html>
|