• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Test suite entry/exit fixture</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="../fixtures.html" title="Fixtures">
9<link rel="prev" href="case.html" title="Test case fixture">
10<link rel="next" href="global.html" title="Global fixture">
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="case.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fixtures.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="global.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h4 class="title">
27<a name="boost_test.tests_organization.fixtures.per_test_suite_fixture"></a><a class="link" href="per_test_suite_fixture.html" title="Test suite entry/exit fixture">Test
28        suite entry/exit fixture</a>
29</h4></div></div></div>
30<p>
31          It is possible to define a test suite entry/exit fixture, so that the
32          <code class="computeroutput"><span class="identifier">setup</span></code> function is called
33          only once upon entering the test suite, prior to running any of its test
34          cases. Similarly the <code class="computeroutput"><span class="identifier">teardown</span></code>
35          function is also called only once upon the test suite exit, after all the
36          enclosed test cases have been run. This is facilitated by the <span class="emphasis"><em>decorator</em></span>
37          <a class="link" href="../../utf_reference/test_org_reference/decorator_fixture.html" title="fixture (decorator)"><code class="computeroutput"><span class="identifier">fixture</span></code></a>.
38        </p>
39<h6>
40<a name="boost_test.tests_organization.fixtures.per_test_suite_fixture.h0"></a>
41          <span class="phrase"><a name="boost_test.tests_organization.fixtures.per_test_suite_fixture.example_descr"></a></span><a class="link" href="per_test_suite_fixture.html#boost_test.tests_organization.fixtures.per_test_suite_fixture.example_descr">Example:
42          Test suite entry/exit fixture</a>
43        </h6>
44<div class="informaltable"><table class="table">
45<colgroup><col></colgroup>
46<thead><tr><th>
47                  <p>
48                    Code
49                  </p>
50                </th></tr></thead>
51<tbody><tr><td>
52<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">fixture_03</span>
53<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>
54<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>
55
56<span class="keyword">struct</span> <span class="identifier">F</span> <span class="special">{</span>
57  <span class="identifier">F</span><span class="special">()</span>  <span class="special">{</span> <span class="identifier">BOOST_TEST_MESSAGE</span><span class="special">(</span> <span class="string">"setup fixture"</span> <span class="special">);</span> <span class="special">}</span>
58  <span class="special">~</span><span class="identifier">F</span><span class="special">()</span> <span class="special">{</span> <span class="identifier">BOOST_TEST_MESSAGE</span><span class="special">(</span> <span class="string">"teardown fixture"</span> <span class="special">);</span> <span class="special">}</span>
59<span class="special">};</span>
60
61<span class="identifier">BOOST_AUTO_TEST_SUITE</span><span class="special">(</span><span class="identifier">s</span><span class="special">,</span> <span class="special">*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">fixture</span><span class="special">&lt;</span><span class="identifier">F</span><span class="special">&gt;())</span>
62
63  <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case1</span><span class="special">)</span>
64  <span class="special">{</span>
65    <span class="identifier">BOOST_TEST_MESSAGE</span><span class="special">(</span><span class="string">"running test_case1"</span><span class="special">);</span>
66    <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="keyword">true</span><span class="special">);</span>
67  <span class="special">}</span>
68
69  <span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case2</span><span class="special">)</span>
70  <span class="special">{</span>
71    <span class="identifier">BOOST_TEST_MESSAGE</span><span class="special">(</span><span class="string">"running test_case2"</span><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>
74
75<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span>
76</pre>
77                </td></tr></tbody>
78</table></div>
79<div class="informaltable"><table class="table">
80<colgroup><col></colgroup>
81<thead><tr><th>
82                  <p>
83                    Output
84                  </p>
85                </th></tr></thead>
86<tbody><tr><td>
87<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">fixture_03</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">message</span>
88<span class="identifier">Running</span> <span class="number">2</span> <span class="identifier">test</span> <span class="identifier">cases</span><span class="special">...</span>
89<span class="identifier">setup</span> <span class="identifier">fixture</span>
90<span class="identifier">running</span> <span class="identifier">test_case1</span>
91<span class="identifier">running</span> <span class="identifier">test_case2</span>
92<span class="identifier">teardown</span> <span class="identifier">fixture</span>
93
94<span class="special">***</span> <span class="identifier">No</span> <span class="identifier">errors</span> <span class="identifier">detected</span>
95</pre>
96                </td></tr></tbody>
97</table></div>
98<p>
99          In case of this fixture type, however, it is not possible to access any
100          members of the fixture object.
101        </p>
102<div class="caution"><table border="0" summary="Caution">
103<tr>
104<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
105<th align="left">Caution</th>
106</tr>
107<tr><td align="left" valign="top"><p>
108            This is not equivalent to using the method described <a class="link" href="case.html#test_case_fixture_subtree">here</a>.
109          </p></td></tr>
110</table></div>
111</div>
112<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
113<td align="left"></td>
114<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p>
115        Distributed under the Boost Software License, Version 1.0. (See accompanying
116        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>)
117      </p>
118</div></td>
119</tr></table>
120<hr>
121<div class="spirit-nav">
122<a accesskey="p" href="case.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fixtures.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="global.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
123</div>
124</body>
125</html>
126