Boost logo

Boost :

Subject: Re: [boost] [test] Automatic registration of tests created with BOOST_PARAM_TEST_CASE
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2009-05-10 05:17:04


Jan Stolarek <fremenzone <at> poczta.onet.pl> writes:

>
> > Boost.Test do not support this setup out of the box
>
> It seems to me that there's no unit testing framework for C++ that would
> support that (please correct me if I'm wrong).

Boost.Test does support it. It's just require some extra leg work from you.
 
> > Which particular part?
> For example this : "Sub test case names are deduced from the macro argument
> test_case_name. If you prefer to assign different test case names, you need
> to use the underlying make_test_case interface instead." More details on that
> would be nice. It would also be great to add more complex examples. Examples
> for each section are clear, however problems arise when one tries to combine
> concepts from many sections.

These rather belong to the advanced usage cases. These docs are only in plans.
 
> > This is not a good idea.
> I found it in documentation for Boost 1.34 :
>
http://www.boost.org/doc/libs/1_34_1/libs/test/doc/tests/parameterized_test_test.html

This is not what expected to do. This is my own internal unit test.
 
> > Your best shot probably is to try to do this in global fixture.
> Would this be a good solution if I had many tests with lots of data sets?

Should not matter, but I just tested and global fixture is invoked too late.
 
> > You can implement your own generator.
> Could you point me to example on how to do that?

You can look into the code. There are at least two implemented there.

> >Also you probably should register your test units directly under
> >framework::master_test_suite()
> As mentioned in my fisrt mail I have tried that but with no result. It seems
> that I got something wrong with what I can add to master test suite.

Here an example that works fine:

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/parameterized_test.hpp>
using namespace boost::unit_test;

// STL
#include <vector>
#include <string>

//____________________________________________________________________________//

// this free function is invoked with all parameters specified in a list
void check_string( std::string const& s )
{
    // reports 'error in "check_string": test s.substr( 0, 3 ) == "hdr" failed
[actual_value != hdr]'
    BOOST_CHECK_EQUAL( s.substr( 0, 3 ), "hdr" );
}

//____________________________________________________________________________//

static struct Setup { Setup() {
 framework::master_test_suite().p_name.value =
    "Automatically registered param test case";

    // parameters have no requirements to stay alive beyond the next statement
    std::string const params[] = { "hdr1 ", "hdr2", "3 " };

    framework::master_test_suite().add(
     BOOST_PARAM_TEST_CASE( &check_string,
                            (std::string const*)params,
                            params+3 ) );
} } _s_setup;

//____________________________________________________________________________//


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk