1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Enabling or disabling test unit execution</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="tests_grouping.html" title="Grouping tests into logical units by labels"> 10<link rel="next" href="semantic.html" title="Adding semantic to a test"> 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="tests_grouping.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="semantic.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.tests_organization.enabling"></a><a class="link" href="enabling.html" title="Enabling or disabling test unit execution">Enabling or disabling 28 test unit execution</a> 29</h3></div></div></div> 30<p> 31 The <span class="emphasis"><em>Unit Test Framework</em></span> provides a way for enabling 32 or disabling a test unit execution. If a test case is disabled, it will not 33 be run by the test runner. If a test suite is disabled, its status is inherited 34 by the test units under its subtree, unless otherwise specified. 35 </p> 36<p> 37 The run status can be overridden by the command line parameters: by providing 38 the appropriate arguments to the command line, a disabled test may still 39 be executed. The <a class="link" href="../runtime_config/test_unit_filtering.html" title="Test unit filtering">test 40 unit filtering</a> section covers this feature in details. 41 </p> 42<div class="warning"><table border="0" summary="Warning"> 43<tr> 44<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../doc/src/images/warning.png"></td> 45<th align="left">Warning</th> 46</tr> 47<tr><td align="left" valign="top"> 48<p> 49 There is a difference between a disabled test and a skipped test: 50 </p> 51<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 52<li class="listitem"> 53 a disabled test has a run status set to disabled, and is completely 54 discarded by the <span class="emphasis"><em>Unit Test Framework</em></span>. 55 </li> 56<li class="listitem"> 57 a skipped test is a test that has a run status set to enabled, but 58 which execution has been skipped at runtime. 59 </li> 60</ul></div> 61</td></tr> 62</table></div> 63<h4> 64<a name="boost_test.tests_organization.enabling.h0"></a> 65 <span class="phrase"><a name="boost_test.tests_organization.enabling.unconditional_run_status"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.unconditional_run_status">Unconditional 66 run status</a> 67 </h4> 68<p> 69 Decorator <a class="link" href="../utf_reference/test_org_reference/decorator_enabled.html" title="enabled / disabled (decorator)"><code class="computeroutput"><span class="identifier">disabled</span></code></a> indicates that the test 70 unit's <a class="link" href="../runtime_config/test_unit_filtering.html#ref_default_run_status"><span class="emphasis"><em>default run status</em></span></a> 71 is <span class="emphasis"><em>false</em></span>. This means that that test cases inside this 72 test unit will not be run by default, unless otherwise specified. Decorator 73 <a class="link" href="../utf_reference/test_org_reference/decorator_enabled.html" title="enabled / disabled (decorator)"><code class="computeroutput"><span class="identifier">enabled</span></code></a> indicates that the test 74 unit's default run status is <span class="emphasis"><em>true</em></span>. This means that that 75 test cases inside this test unit will be run by default, unless otherwise 76 specified. 77 </p> 78<h6> 79<a name="boost_test.tests_organization.enabling.h1"></a> 80 <span class="phrase"><a name="boost_test.tests_organization.enabling.example_descr"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.example_descr">Example: decorators 81 enabled and disabled</a> 82 </h6> 83<div class="informaltable"><table class="table"> 84<colgroup><col></colgroup> 85<thead><tr><th> 86 <p> 87 Code 88 </p> 89 </th></tr></thead> 90<tbody><tr><td> 91<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_05</span> 92<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> 93<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> 94 95<span class="identifier">BOOST_AUTO_TEST_SUITE</span><span class="special">(</span><span class="identifier">suite1</span><span class="special">,</span> <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">disabled</span><span class="special">())</span> 96 97 <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test1</span><span class="special">)</span> 98 <span class="special">{</span> 99 <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> 100 <span class="special">}</span> 101 102 <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test2</span><span class="special">,</span> <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">enabled</span><span class="special">())</span> 103 <span class="special">{</span> 104 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="number">2</span> <span class="special">!=</span> <span class="number">2</span><span class="special">);</span> 105 <span class="special">}</span> 106 107<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span> 108</pre> 109 </td></tr></tbody> 110</table></div> 111<div class="informaltable"><table class="table"> 112<colgroup><col></colgroup> 113<thead><tr><th> 114 <p> 115 Output 116 </p> 117 </th></tr></thead> 118<tbody><tr><td> 119<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></span> <span class="identifier">decorator_05</span> 120<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span> 121<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">14</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"suite1/test2"</span><span class="special">:</span> <span class="identifier">check</span> <span class="number">2</span> <span class="special">!=</span> <span class="number">2</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">2</span> <span class="special">==</span> <span class="number">2</span><span class="special">]</span> 122 123<span class="special">***</span> <span class="number">1</span> <span class="identifier">failure</span> <span class="identifier">is</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_05"</span> 124 125 126<span class="special">></span> <span class="identifier">decorator_05</span> <span class="special">--</span><span class="identifier">list_content</span> 127<span class="identifier">suite1</span><span class="special">*</span> 128 <span class="identifier">test1</span> 129 <span class="identifier">test2</span><span class="special">*</span> 130</pre> 131 </td></tr></tbody> 132</table></div> 133<p> 134 Syntactically, it is possible to apply both decorators <code class="computeroutput"><span class="identifier">enabled</span></code> 135 and <code class="computeroutput"><span class="identifier">disabled</span></code> to the same 136 test unit. This is reported as set-up error when the test program is run. 137 </p> 138<h4> 139<a name="boost_test.tests_organization.enabling.h2"></a> 140 <span class="phrase"><a name="boost_test.tests_organization.enabling.compilation_time_run_status"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.compilation_time_run_status">Compilation-time 141 run status</a> 142 </h4> 143<p> 144 Decorator <a class="link" href="../utf_reference/test_org_reference/decorator_enable_if.html" title="enable_if (decorator)"><code class="computeroutput"><span class="identifier">enable_if</span></code></a> indicates that the test 145 unit's <a class="link" href="../runtime_config/test_unit_filtering.html#ref_default_run_status"><span class="emphasis"><em>default run status</em></span></a> 146 is either <span class="emphasis"><em>true</em></span> or <span class="emphasis"><em>false</em></span>, depending 147 on the value of <code class="computeroutput"><span class="identifier">Condition</span></code>. 148 This means that that test cases inside this test unit will or will not be 149 run by default. 150 </p> 151<h6> 152<a name="boost_test.tests_organization.enabling.h3"></a> 153 <span class="phrase"><a name="boost_test.tests_organization.enabling.example_descr0"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.example_descr0">Example: 154 decorator enable_if</a> 155 </h6> 156<div class="informaltable"><table class="table"> 157<colgroup><col></colgroup> 158<thead><tr><th> 159 <p> 160 Code 161 </p> 162 </th></tr></thead> 163<tbody><tr><td> 164<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_06</span> 165<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> 166<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> 167 168<span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">io_implemented</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">;</span> 169<span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">db_implemented</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">;</span> 170 171<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_io</span><span class="special">,</span> 172 <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">enable_if</span><span class="special"><</span><span class="identifier">io_implemented</span><span class="special">>())</span> 173<span class="special">{</span> 174 <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> 175<span class="special">}</span> 176 177<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_db</span><span class="special">,</span> 178 <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">enable_if</span><span class="special"><</span><span class="identifier">db_implemented</span><span class="special">>())</span> 179<span class="special">{</span> 180 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="number">2</span> <span class="special">!=</span> <span class="number">2</span><span class="special">);</span> 181<span class="special">}</span> 182</pre> 183 </td></tr></tbody> 184</table></div> 185<div class="informaltable"><table class="table"> 186<colgroup><col></colgroup> 187<thead><tr><th> 188 <p> 189 Output 190 </p> 191 </th></tr></thead> 192<tbody><tr><td> 193<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></span> <span class="identifier">decorator_06</span> 194<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span> 195<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">11</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_io"</span><span class="special">:</span> <span class="identifier">check</span> <span class="number">1</span> <span class="special">!=</span> <span class="number">1</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">1</span> <span class="special">==</span> <span class="number">1</span><span class="special">]</span> 196 197<span class="special">***</span> <span class="number">1</span> <span class="identifier">failure</span> <span class="identifier">is</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_06"</span> 198 199 200<span class="special">></span> <span class="identifier">decorator_06</span> <span class="special">--</span><span class="identifier">list_content</span> 201<span class="identifier">test_io</span><span class="special">*</span> 202<span class="identifier">test_db</span> 203</pre> 204 </td></tr></tbody> 205</table></div> 206<p> 207 Decorator <code class="computeroutput"><span class="identifier">enable_if</span><span class="special"><</span><span class="keyword">true</span><span class="special">>()</span></code> 208 is equivalent to decorator <code class="computeroutput"><span class="identifier">enabled</span><span class="special">()</span></code>. Similarly, <code class="computeroutput"><span class="identifier">enable_if</span><span class="special"><</span><span class="keyword">false</span><span class="special">>()</span></code> is equivalent to decorator <code class="computeroutput"><span class="identifier">disabled</span><span class="special">()</span></code>. 209 </p> 210<h4> 211<a name="boost_test.tests_organization.enabling.h4"></a> 212 <span class="phrase"><a name="boost_test.tests_organization.enabling.runtime_run_status"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.runtime_run_status">Runtime 213 run status</a> 214 </h4> 215<p> 216 Decorator <a class="link" href="../utf_reference/test_org_reference/decorator_precondition.html" title="precondition (decorator)"><code class="computeroutput"><span class="identifier">precondition</span></code></a> associates a <span class="emphasis"><em>predicate</em></span> 217 with a test unit. Before the test unit is executed, the predicate is evaluated 218 with the test unit's ID passed as the argument. If it evaluates to <code class="computeroutput"><span class="keyword">false</span></code>, execution of the test unit is skipped. 219 Skipping a test suite means skipping the execution of every test unit inside. 220 </p> 221<div class="tip"><table border="0" summary="Tip"> 222<tr> 223<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../doc/src/images/tip.png"></td> 224<th align="left">Tip</th> 225</tr> 226<tr><td align="left" valign="top"><p> 227 The precondition may return an <code class="computeroutput"><a class="link" href="../../boost/test_tools/assertion_result.html" title="Class assertion_result">assertion_result</a></code> 228 instead of a boolean. In that case, the message contained in the <code class="computeroutput"><span class="identifier">assertion_result</span></code> will be printed by the 229 <span class="emphasis"><em>Unit Test Framework</em></span>. 230 </p></td></tr> 231</table></div> 232<h6> 233<a name="boost_test.tests_organization.enabling.h5"></a> 234 <span class="phrase"><a name="boost_test.tests_organization.enabling.example_descr1"></a></span><a class="link" href="enabling.html#boost_test.tests_organization.enabling.example_descr1">Example: 235 decorator precondition</a> 236 </h6> 237<div class="informaltable"><table class="table"> 238<colgroup><col></colgroup> 239<thead><tr><th> 240 <p> 241 Code 242 </p> 243 </th></tr></thead> 244<tbody><tr><td> 245<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_08</span> 246<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> 247<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> 248<span class="keyword">namespace</span> <span class="identifier">tt</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">test_tools</span><span class="special">;</span> 249 250<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test1</span><span class="special">)</span> 251<span class="special">{</span> 252 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">true</span><span class="special">);</span> 253<span class="special">}</span> 254 255<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test2</span><span class="special">)</span> 256<span class="special">{</span> 257 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span> 258<span class="special">}</span> 259 260<span class="keyword">struct</span> <span class="identifier">if_either</span> 261<span class="special">{</span> 262 <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">tc1</span><span class="special">,</span> <span class="identifier">tc2</span><span class="special">;</span> 263 <span class="identifier">if_either</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">t1</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">t2</span><span class="special">)</span> 264 <span class="special">:</span> <span class="identifier">tc1</span><span class="special">(</span><span class="identifier">t1</span><span class="special">),</span> <span class="identifier">tc2</span><span class="special">(</span><span class="identifier">t2</span><span class="special">)</span> <span class="special">{}</span> 265 266 <span class="identifier">tt</span><span class="special">::</span><span class="identifier">assertion_result</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">utf</span><span class="special">::</span><span class="identifier">test_unit_id</span><span class="special">)</span> 267 <span class="special">{</span> 268 <span class="keyword">auto</span><span class="special">&</span> <span class="identifier">master</span> <span class="special">=</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">framework</span><span class="special">::</span><span class="identifier">master_test_suite</span><span class="special">();</span> 269 <span class="keyword">auto</span><span class="special">&</span> <span class="identifier">collector</span> <span class="special">=</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">results_collector_t</span><span class="special">::</span><span class="identifier">instance</span><span class="special">();</span> 270 <span class="keyword">auto</span><span class="special">&</span> <span class="identifier">test1_result</span> <span class="special">=</span> <span class="identifier">collector</span><span class="special">.</span><span class="identifier">results</span><span class="special">(</span><span class="identifier">master</span><span class="special">.</span><span class="identifier">get</span><span class="special">(</span><span class="identifier">tc1</span><span class="special">));</span> 271 <span class="keyword">auto</span><span class="special">&</span> <span class="identifier">test2_result</span> <span class="special">=</span> <span class="identifier">collector</span><span class="special">.</span><span class="identifier">results</span><span class="special">(</span><span class="identifier">master</span><span class="special">.</span><span class="identifier">get</span><span class="special">(</span><span class="identifier">tc2</span><span class="special">));</span> 272 273 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">test1_result</span><span class="special">.</span><span class="identifier">passed</span><span class="special">()</span> <span class="special">||</span> <span class="identifier">test2_result</span><span class="special">.</span><span class="identifier">passed</span><span class="special">())</span> 274 <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span> 275 276 <span class="identifier">tt</span><span class="special">::</span><span class="identifier">assertion_result</span> <span class="identifier">ans</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span> 277 <span class="identifier">ans</span><span class="special">.</span><span class="identifier">message</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">tc1</span> <span class="special"><<</span> <span class="string">" and "</span> <span class="special"><<</span> <span class="identifier">tc2</span> <span class="special"><<</span> <span class="string">" failed"</span><span class="special">;</span> 278 <span class="keyword">return</span> <span class="identifier">ans</span><span class="special">;</span> 279 <span class="special">}</span> 280<span class="special">};</span> 281 282<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test3</span><span class="special">,</span> 283 <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">precondition</span><span class="special">(</span><span class="identifier">if_either</span><span class="special">(</span><span class="string">"test1"</span><span class="special">,</span> <span class="string">"test2"</span><span class="special">)))</span> 284<span class="special">{</span> 285 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span> 286<span class="special">}</span> 287 288<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test4</span><span class="special">,</span> 289 <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">precondition</span><span class="special">(</span><span class="identifier">if_either</span><span class="special">(</span><span class="string">"test2"</span><span class="special">,</span> <span class="string">"test3"</span><span class="special">)))</span> 290<span class="special">{</span> 291 <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">false</span><span class="special">);</span> 292<span class="special">}</span> 293</pre> 294 </td></tr></tbody> 295</table></div> 296<div class="informaltable"><table class="table"> 297<colgroup><col></colgroup> 298<thead><tr><th> 299 <p> 300 Output 301 </p> 302 </th></tr></thead> 303<tbody><tr><td> 304<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></span> <span class="identifier">decorator_08</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">test_suite</span> 305<span class="identifier">Running</span> <span class="number">4</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span> 306<span class="identifier">Entering</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_08"</span> 307<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">6</span><span class="special">):</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test1"</span> 308<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">6</span><span class="special">):</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test1"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">1</span><span class="identifier">ms</span> 309<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">11</span><span class="special">):</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test2"</span> 310<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">13</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test2"</span><span class="special">:</span> <span class="identifier">check</span> <span class="keyword">false</span> <span class="identifier">has</span> <span class="identifier">failed</span> 311<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">11</span><span class="special">):</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test2"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">2</span><span class="identifier">ms</span> 312<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">39</span><span class="special">):</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test3"</span> 313<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">41</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test3"</span><span class="special">:</span> <span class="identifier">check</span> <span class="keyword">false</span> <span class="identifier">has</span> <span class="identifier">failed</span> 314<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">39</span><span class="special">):</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test3"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">2</span><span class="identifier">ms</span> 315<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">45</span><span class="special">):</span> <span class="identifier">Test</span> <span class="keyword">case</span> <span class="string">"test4"</span> <span class="identifier">is</span> <span class="identifier">skipped</span> <span class="identifier">because</span> <span class="identifier">test2</span> <span class="keyword">and</span> <span class="identifier">test3</span> <span class="identifier">failed</span> 316<span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_08"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">16</span><span class="identifier">ms</span> 317 318<span class="special">***</span> <span class="number">2</span> <span class="identifier">failures</span> <span class="identifier">are</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"decorator_08"</span> 319</pre> 320 </td></tr></tbody> 321</table></div> 322<p> 323 In the example above, the user defined a custom predicate <code class="computeroutput"><span class="identifier">if_either</span></code> 324 that evaluates to <code class="computeroutput"><span class="keyword">true</span></code> if at 325 least one of the two specified tests passed. (It assumes that the tests are 326 registered in the specific order.) 327 </p> 328<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 329<li class="listitem"> 330 Test case <code class="computeroutput"><span class="identifier">test3</span></code> has a 331 precondition that at either <code class="computeroutput"><span class="identifier">test1</span></code> 332 or <code class="computeroutput"><span class="identifier">test2</span></code> passed. The 333 precondition is satisfied, therefore <code class="computeroutput"><span class="identifier">test3</span></code> 334 is run (and fails), 335 </li> 336<li class="listitem"> 337 test case <code class="computeroutput"><span class="identifier">test4</span></code> has a 338 precondition that either <code class="computeroutput"><span class="identifier">test2</span></code> 339 or <code class="computeroutput"><span class="identifier">test3</span></code> passed. Since 340 they both failed, the precondition is not satisfied, therefore <code class="computeroutput"><span class="identifier">test4</span></code> is skipped. 341 </li> 342</ul></div> 343<div class="note"><table border="0" summary="Note"> 344<tr> 345<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td> 346<th align="left">Note</th> 347</tr> 348<tr><td align="left" valign="top"><p> 349 A <a class="link" href="../utf_reference/test_org_reference/decorator_precondition.html" title="precondition (decorator)"><code class="computeroutput"><span class="identifier">precondition</span></code></a> that evaluates to 350 <code class="computeroutput"><span class="keyword">false</span></code> does not yield an error 351 and does not fail the attached unit test. However the <span class="emphasis"><em>Unit Test 352 Framework</em></span> returns an error if the test tree is empty (see <a class="link" href="test_tree/test_tree_content.html" title="Test tree content">this 353 section</a> for more details). 354 </p></td></tr> 355</table></div> 356</div> 357<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 358<td align="left"></td> 359<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p> 360 Distributed under the Boost Software License, Version 1.0. (See accompanying 361 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>) 362 </p> 363</div></td> 364</tr></table> 365<hr> 366<div class="spirit-nav"> 367<a accesskey="p" href="tests_grouping.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="semantic.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 368</div> 369</body> 370</html> 371