Boost.Test > Components > The Unit Test Framework > Components > The Test Case > The free function based test case
Boost Test logo

The free function based test case


defined in unit_test_suite.hpp

class function_test_case : public test_case
    ... // Implementation

Simplest and most widely used form of test cases. Instances of the class function_test_case are created by the framework for the user supplied pointer to free function with the following specification: void (*fct)(). Note void return type. To report a testing results one should use the Test Tools instead of returning result code.


To create a test case based on your test function use the following macro:

BOOST_TEST_CASE( free_function_address ).

BOOST_TEST_CASE creates a new instance of the class function_test_case and returns a pointer to the base class test_case. In most cases you will use it as an argument to the method test_suite::add(...). The only parameter to above macro is the pointer of free function - body of the test case.

void test_feature1()

ts->add( BOOST_TEST_CASE( &test_feature1 ) );
#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;

// most frequently you implement test cases as a free functions
void free_test_function()
    BOOST_CHECK( 2 == 1 );

init_unit_test_suite( int argc, char* argv[] ) {
    test_suite* test= BOOST_TEST_SUITE( "Example" );

    test->add( BOOST_TEST_CASE( &free_test_function )

    return test;