Home > The Unit Test Framework > User's guide > Test organization > Test suite > Manual registration
PrevNext

Manually registered test suites

To create a test suite manually, employ the macro BOOST_TEST_SUITE:

BOOST_TEST_SUITE(test_suite_name)

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.

[Note] Note

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.

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.

Example15.Manually registered test suites

#include <boost/test/included/unit_test.hpp>
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->add( BOOST_TEST_CASE( &test_case1 ) );
    ts1->add( BOOST_TEST_CASE( &test_case2 ) );

    test_suite* ts2 = BOOST_TEST_SUITE( "test_suite2" );
    ts2->add( BOOST_TEST_CASE( &test_case3 ) );
    ts2->add( BOOST_TEST_CASE( &test_case4 ) );

    framework::master_test_suite().add( ts1 );
    framework::master_test_suite().add( ts2 );

    return 0;
}

//____________________________________________________________________________//
Source code | Show output
> 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

This example creates a test tree, which can be represented by the following hierarchy:


PrevUpHomeNext