Boost.Test > Components > The Unit Test Framework > Components > The Test Case > The parameterized function test case

# The parameterized free function based test case

##### Definition

defined in unit_test_suite.hpp

##### Synopsis

    template <typename ParamIterator, typename ParameterType>
    class parametrized_function_test_case : public test_case
    {
        ... // Implementation
    };

##### Description

Instances of the class parametrized_function_test_case are created by the framework for the supplied user's free function with the following specification: void (*fct)( ParameterType ).

##### Construction

To create an instance of the class parametrized_function_test_case use the following macro:

BOOST_PARAM_TEST_CASE( free_function_address, first_parameter, last_parameter ).

The first macro parameter is an address of free function - body of the test case. The first_parameter and last_parameter are begin and end iterators for the list of parameters accordingly. BOOST_PARAM_TEST_CASE creates a new instance of the class parametrized_function_test_case and returns a pointer to the abstract class test_case. In most cases you will use it as an argument to the method test_suite::add(...). Be aware that the parametrized_function_test_case does not store list of parameters internally. The user should make sure that parameters list will not be destroyed until the test case is run. That's why it not recommended to create a parameters list as local variable in init_unit_test_suite. A simple way to handle a parameters list lifetime is to place it into a user defined test suite class.

##### Example

    void test_file_reader( std::string const& file_name )
    {
        ...
    }

    struct reader_testing : public boost::unit_test::test_suite
    {
        reader_testing()
        {
            files_to_test.push_back( "file 1" );
            ...

            files_to_test.push_back( "file N" );

            add( BOOST_PARAM_TEST_CASE( &test_file_reader,
                                        files_to_test.begin(),
                                        files_to_test.end() );
        }
        std::list<std::string> files_to_test;
    };
    ...
    ts->add( new reader_testing );