blob: ff1e0ba52f452fc76aeb0ec4907959630bd80f55 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test suite level fixture</title>
<link rel="stylesheet" href="../../../../style/style.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
<link rel="home" href="../../../index.html" title="Boost Test Library">
<link rel="up" href="../fixture.html" title="Fixtures or let me repeat myself">
<link rel="prev" href="per-test-case.html" title="Per test case fixture">
<link rel="next" href="global.html" title="Global fixture">
<script language="JavaScript1.2" src="../../../../js/boost-test.js"></script>
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table width="100%"><tr>
<td width="10%"><a href="../../../index.html"><img alt="Home" width="229" height="61" border="0" src="../../../../../../../libs/test/docbook/img/boost.test.logo.png"></a></td>
<td valign="middle" align="left"> &gt; <a href="../../../utf.html">The Unit Test Framework</a> &gt; <a href="../../user-guide.html">User's guide</a><a href="../../testing-tools.html">
&gt;
</a><a href="../fixture.html">Fixtures</a><a href="../test-output.html">
&gt;
</a><b>Test suite shared</b>
</td>
<td><div class="spirit-nav">
<a href="per-test-case.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a href="global.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
</div></td>
</tr></table>
<hr>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
<a name="utf.user-guide.fixture.test-suite-shared"></a>Test suite level fixture</h5></div></div></div>
<p class="first-line-indented">
If all test cases in a test require the same fixture (you can group test cases in the test suite based on a
fixture required) you can make another step toward an automation of a test fixture assignment. To assign the
same shared fixture for all test cases in a test suite use the macro BOOST_FIXTURE_TEST_SUITE in place of the
macro <code class="computeroutput"><a class="link" href="../test-organization/auto-test-suite.html#BOOST_AUTO_TEST_SUITE">BOOST_AUTO_TEST_SUITE</a></code> for automated test suite creation and registration.
</p>
<pre class="inline-synopsis">
<a name="BOOST_FIXTURE_TEST_SUITE"></a>BOOST_FIXTURE_TEST_SUITE(<span class="emphasis"><em>suite_name</em></span>, <span class="emphasis"><em>fixure_name</em></span>)</pre>
<p class="first-line-indented">
Once again the only difference from the macro <code class="computeroutput"><a class="link" href="../test-organization/auto-test-suite.html#BOOST_AUTO_TEST_SUITE">BOOST_AUTO_TEST_SUITE</a></code> usage is the presence of
an extra argument - the fixture name. And now, you not only have direct access to the public and protected members
of the fixture, but also do not need to refer to the fixture name in test case definition. All test cases assigned
the same fixture automatically.
</p>
<div class="tip"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../doc/html/images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>
If necessary you can reset the fixture for a particular test case with the use of the macro
<code class="computeroutput"><a class="link" href="per-test-case.html#BOOST_FIXTURE_TEST_CASE">BOOST_FIXTURE_TEST_CASE</a></code>.
</p></td></tr>
</table></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/html/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
The fixture assignment is "deep". In other words unless reset by another
<code class="computeroutput"><a class="link" href="test-suite-shared.html#BOOST_FIXTURE_TEST_SUITE">BOOST_FIXTURE_TEST_SUITE</a></code> or <code class="computeroutput"><a class="link" href="per-test-case.html#BOOST_FIXTURE_TEST_CASE">BOOST_FIXTURE_TEST_CASE</a></code> definition the
same fixture is assigned to all test cases, including ones that belong to the sub test suites.
</p></td></tr>
</table></div>
<div class="example">
<a name="utf.user-guide.fixture.test-suite-shared.example19"></a><p class="title"><b>Example 24. Test suite level fixture</b></p>
<div class="example-contents">
<pre class="programlisting">#define BOOST_TEST_MODULE example
#include &lt;boost/test/included/unit_test.hpp&gt;
struct F {
F() : i( 0 ) { BOOST_TEST_MESSAGE( "setup fixture" ); }
~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
int i;
};
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_SUITE( s, F )
BOOST_AUTO_TEST_CASE( test_case1 )
{
BOOST_CHECK( i == 1 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_case2 )
{
BOOST_CHECK_EQUAL( i, 0 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_SUITE_END()
</pre>
<table class="simplelist" border="0" summary="Simple list"><tr>
<td><code class="literal"><a href="../../../../src/examples/example19.cpp" target="_top">Source code</a></code></td>
<td> | </td>
<td><code class="literal"><a href="#" target="_top" id="id652984" onclick="toggle_element( 'example19-output', 'id652984', 'Show output', 'Hide output' ); return false;">Show output</a></code></td>
</tr></table>
<pre class="example-output" id="example19-output">&gt; example
Running 2 test cases...
test.cpp(17): error in "test_case1": check i == 1 failed
*** 1 failure detected in test suite "example"
</pre>
</div>
</div>
<br class="example-break">
</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-2007 Gennadiy Rozental</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="per-test-case.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fixture.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="global.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>