blob: 39da0505d4cf12d9a58cb015a062855357aeef7a [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Manually registered test suites</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="test-suite.html" title="Test suite">
<link rel="prev" href="test-suite.html" title="Test suite">
<link rel="next" href="auto-test-suite.html" title="Test suites with automated registration">
<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="../test-organization.html">Test organization</a><a href="../fixture.html">
&gt;
</a><a href="test-suite.html">Test suite</a><a href="expected-failures.html">
&gt;
</a><b>Manual registration</b>
</td>
<td><div class="spirit-nav">
<a href="test-suite.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a href="auto-test-suite.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><h6 class="title">
<a name="utf.user-guide.test-organization.manual-test-suite"></a>Manually registered test suites</h6></div></div></div>
<p class="first-line-indented">
To create a test suite manually, employ the macro BOOST_TEST_SUITE:
</p>
<pre class="inline-synopsis">
<a name="BOOST_TEST_SUITE"></a>BOOST_TEST_SUITE(<span class="emphasis"><em>test_suite_name</em></span>)</pre>
<p class="first-line-indented">
BOOST_TEST_SUITE creates an instance of the class boost::unit_test::test_suite and returns a pointer to the
constructed instance. Alternatively you can create an instance of class boost::unit_test::test_suite yourself.
</p>
<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>
boost::unit_test::test_suite instances have to be allocated on the heap and the compiler won't allow you
to create one on the stack.
</p></td></tr>
</table></div>
<p class="first-line-indented">
Newly created test suite has to be registered in a parent one using add interface. Both test suite creation and
registration is performed in the test module initialization function.
</p>
<div class="example">
<a name="utf.user-guide.test-organization.manual-test-suite.example11"></a><p class="title"><b>Example 15. Manually registered test suites</b></p>
<div class="example-contents">
<pre class="programlisting">#include &lt;boost/test/included/unit_test.hpp&gt;
using namespace boost::unit_test;
//____________________________________________________________________________//
void test_case1() { /* : */ }
void test_case2() { /* : */ }
void test_case3() { /* : */ }
void test_case4() { /* : */ }
//____________________________________________________________________________//
test_suite*
init_unit_test_suite( int argc, char* argv[] )
{
test_suite* ts1 = BOOST_TEST_SUITE( "test_suite1" );
ts1-&gt;add( BOOST_TEST_CASE( &amp;test_case1 ) );
ts1-&gt;add( BOOST_TEST_CASE( &amp;test_case2 ) );
test_suite* ts2 = BOOST_TEST_SUITE( "test_suite2" );
ts2-&gt;add( BOOST_TEST_CASE( &amp;test_case3 ) );
ts2-&gt;add( BOOST_TEST_CASE( &amp;test_case4 ) );
framework::master_test_suite().add( ts1 );
framework::master_test_suite().add( ts2 );
return 0;
}
//____________________________________________________________________________//
</pre>
<table class="simplelist" border="0" summary="Simple list"><tr>
<td><code class="literal"><a href="../../../../src/examples/example11.cpp" target="_top">Source code</a></code></td>
<td> | </td>
<td><code class="literal"><a href="#" target="_top" id="id651101" onclick="toggle_element( 'example11-output', 'id651101', 'Show output', 'Hide output' ); return false;">Show output</a></code></td>
</tr></table>
<pre class="example-output" id="example11-output">&gt; example --log_level=test_suite
Running 4 test cases...
Entering test suite "Master Test Suite"
Entering test suite "test_suite1"
Entering test case "test_case1"
Leaving test case "test_case1"
Entering test case "test_case2"
Leaving test case "test_case2"
Leaving test suite "test_suite1"
Entering test suite "test_suite2"
Entering test case "test_case3"
Leaving test case "test_case3"
Entering test case "test_case4"
Leaving test case "test_case4"
Leaving test suite "test_suite2"
Leaving test suite "Master Test Suite"
*** No errors detected
</pre>
</div>
</div>
<br class="example-break"><p class="first-line-indented">
This example creates a test tree, which can be represented by the following hierarchy:
</p>
<div class="mediaobject"><img src="../../../../img/class-hier.jpg"></div>
</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="test-suite.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="test-suite.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="auto-test-suite.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>