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">
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>
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>
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>
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.
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
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>.
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>
58 <div class="informaltable"><table class="table">
59 <colgroup><col></colgroup>
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"><</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>
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>
70 <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>
71 <span class="special">{</span>
72 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">true</span><span class="special">);</span>
73 <span class="special">}</span>
75 <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case2</span><span class="special">,</span>
76 <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>
77 <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>
78 <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>
79 <span class="special">{</span>
80 <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>
81 <span class="special">}</span>
85 <div class="informaltable"><table class="table">
86 <colgroup><col></colgroup>
93 <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></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>
94 <span class="identifier">Running</span> <span class="number">2</span> <span class="identifier">test</span> <span class="identifier">cases</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>
99 <span class="special">></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>
100 <span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span>
102 <span class="special">***</span> <span class="identifier">No</span> <span class="identifier">errors</span> <span class="identifier">detected</span>
107 Each decorator in the list is preceded by an asterisk (<code class="computeroutput"><span class="special">*</span></code>);
108 the subsequent syntax resembles a function call and is specified in detail
109 for each decorator. If there is more than one decorator in the list, they
110 are concatenated with no additional separator; each asterisk indicates the
111 beginning of a decorator. In the above example, test case <code class="computeroutput"><span class="identifier">test_case1</span></code>
112 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
113 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:
114 two of type <code class="computeroutput"><span class="identifier">label</span></code> and one
115 of type <code class="computeroutput"><span class="identifier">description</span></code>.
118 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
119 <td align="left"></td>
120 <td align="right"><div class="copyright-footer">Copyright © 2001-2019 Boost.Test
122 Distributed under the Boost Software License, Version 1.0. (See accompanying
123 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>)
128 <div class="spirit-nav">
129 <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>