3
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4
<title>Per test case fixture</title>
5
<link rel="stylesheet" href="../../../../style/style.css" type="text/css">
6
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
7
<link rel="home" href="../../../index.html" title="Boost Test Library">
8
<link rel="up" href="../fixture.html" title="Fixtures or let me repeat myself">
9
<link rel="prev" href="model.html" title="Generic fixture model">
10
<link rel="next" href="test-suite-shared.html" title="Test suite level fixture">
11
<script language="JavaScript1.2" src="../../../../js/boost-test.js"></script>
13
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14
<table width="100%"><tr>
15
<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>
16
<td valign="middle" align="left"> > <a href="../../../utf.html">The Unit Test Framework</a> > <a href="../../user-guide.html">User's guide</a><a href="../../testing-tools.html">
18
</a><a href="../fixture.html">Fixtures</a><a href="../test-output.html">
20
</a><b>Per test case</b>
22
<td><div class="spirit-nav">
23
<a href="model.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a href="test-suite-shared.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
27
<div class="section" lang="en">
28
<div class="titlepage"><div><div><h5 class="title">
29
<a name="utf.user-guide.fixture.per-test-case"></a>Per test case fixture</h5></div></div></div>
30
<p class="first-line-indented">
31
To automate the task of assigning a fixture for the test case, for test case creation use the macro
32
BOOST_FIXTURE_TEST_CASE in place of the macro <code class="computeroutput"><a class="link" href="../test-organization/auto-nullary-test-case.html#BOOST_AUTO_TEST_CASE">BOOST_AUTO_TEST_CASE</a></code>:
34
<pre class="inline-synopsis">
35
<a name="BOOST_FIXTURE_TEST_CASE"></a>BOOST_FIXTURE_TEST_CASE(<span class="emphasis"><em>test_case_name</em></span>, <span class="emphasis"><em>fixure_name</em></span>)</pre>
36
<p class="first-line-indented">
37
The only difference from the macro <code class="computeroutput"><a class="link" href="../test-organization/auto-nullary-test-case.html#BOOST_AUTO_TEST_CASE">BOOST_AUTO_TEST_CASE</a></code> is the presence of an extra argument
38
- fixture name. Unlike the pure C++ solution you have direct access to the public and protected members of the
39
fixture, though you still need to refer to the fixture name in every test case.
41
<div class="note"><table border="0" summary="Note">
43
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/html/images/note.png"></td>
44
<th align="left">Note</th>
46
<tr><td align="left" valign="top"><p>
47
You can't access private members of fixture, but then why would you make anything private?
51
<a name="utf.user-guide.fixture.per-test-case.example18"></a><p class="title"><b>Example�23.�Per test case fixture</b></p>
52
<div class="example-contents">
53
<p class="first-line-indented">
54
In this example only test_case1 and test_case2 have fixture F assigned. In the next section you going to see
55
what can be done if all test cases in a test suite require the same fixture.
57
<pre class="programlisting">#define BOOST_TEST_MODULE example
58
#include <boost/test/included/unit_test.hpp>
61
F() : i( 0 ) { BOOST_TEST_MESSAGE( "setup fixture" ); }
62
~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
67
BOOST_FIXTURE_TEST_CASE( test_case1, F )
69
BOOST_CHECK( i == 1 );
73
BOOST_FIXTURE_TEST_CASE( test_case2, F )
75
BOOST_CHECK_EQUAL( i, 1 );
78
BOOST_AUTO_TEST_CASE( test_case3 )
83
<table class="simplelist" border="0" summary="Simple list"><tr>
84
<td><code class="literal"><a href="../../../../src/examples/example18.cpp" target="_top">Source code</a></code></td>
86
<td><code class="literal"><a href="#" target="_top" id="id652742" onclick="toggle_element( 'example18-output', 'id652742', 'Show output', 'Hide output' ); return false;">Show output</a></code></td>
88
<pre class="example-output" id="example18-output">> example --log_level=message
89
Running 3 test cases...
91
test.cpp(13): error in "test_case1": check i == 1 failed
94
test.cpp(19): error in "test_case2": check i == 1 failed [0 != 1]
97
*** 2 failures detected in test suite "example"</pre>
100
<br class="example-break">
102
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
103
<td align="left"></td>
104
<td align="right"><div class="copyright-footer">Copyright � 2001-2007 Gennadiy Rozental</div></td>
107
<div class="spirit-nav">
108
<a accesskey="p" href="model.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="test-suite-shared.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>