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-08 04:13:50


JS <fremenzone <at> poczta.onet.pl> writes:

>
> Hi,
>
> I want to create a test that
> a) runs the same testing function with different sets of input data
> AND
> b) registers automatically

Boost.Test do not support this setup out of the box
 
> Obviously I can use BOOST_PARAM_TEST_CASE macro for a), but how do I achieve
> b) at the same time? I've been fighting with the problem for many hours and I
> have no idea how to do it. Unfortunately the documentation is very cryptic.

Which particular part?

> void testMethod( DataSet* data ) {
> /* do something with method that's being tested. Use data somehow */
> BOOST_CHECK( /* assertion */ );
> }
>
> BOOST_AUTO_TEST_CASE( TestName ) {
> DataProvider dataProvider;
> test_suite* test = BOOST_TEST_SUITE( "I don't think the name matters" );
> test->add( BOOST_PARAM_TEST_CASE( &testMethod, dataProvider.dataSet.begin(),
> dataProvider.dataSet.end() ) );
> framework::run( test );
> }

This is not a good idea. You are changing test tree on a fly. Your best shot
probably is to try ot do this in global fixture. You do not necessarily have to
use the macro. class test_suite has add method that expects test_unit_generator
const&. You can implement your own generator. Also you probably should register
your test units directly under framework::master_test_suite()

Gennadiy


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