mirror of
https://github.com/boostorg/test.git
synced 2026-02-02 21:22:10 +00:00
126 lines
6.5 KiB
HTML
Executable File
126 lines
6.5 KiB
HTML
Executable File
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Test suite level fixture</title>
|
|
<link rel="stylesheet" href="../../../../style/style.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
|
|
<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/doc/img/boost.test.logo.png"></a></td>
|
|
<td valign="middle" align="left"> > <a href="../../../utf.html">The Unit Test Framework</a><a href="../../../execution-monitor.html">
|
|
>
|
|
</a><a href="../../user-guide.html">User's guide</a><a href="../../usage-recommendations.html">
|
|
>
|
|
</a><a href="../fixture.html">Fixtures</a><a href="../initialization.html">
|
|
>
|
|
</a><b>Test suite shared</b>
|
|
</td>
|
|
<td><div class="spirit-nav">
|
|
<a href="per-test-case.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a href="global.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="section">
|
|
<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/src/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/src/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 53. Test suite level fixture</b></p>
|
|
<div class="example-contents">
|
|
<pre class="programlisting">#define BOOST_TEST_MODULE example
|
|
#include <boost/test/included/unit_test.hpp>
|
|
|
|
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 border="0" summary="Simple list" class="simplelist"><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="id548812" onclick="toggle_element( 'example19-output', 'id548812', 'Show output', 'Hide output' ); return false;">Show output</a></code></td>
|
|
</tr></table>
|
|
<pre class="example-output" id="example19-output">> 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-2012 Gennadiy Rozental</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="per-test-case.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../fixture.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>
|
|
</div>
|
|
</body>
|
|
</html>
|