[test] Automatic registration of tests created with BOOST_PARAM_TEST_CASE

Hi, I want to create a test that a) runs the same testing function with different sets of input data AND b) registers automatically 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. Here's what I came up with so far: boost-main.cpp : #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MAIN #define BOOST_TEST_MODULE My Master Test Suite #include <boost/test/unit_test.hpp> testSomeFunctions.cpp : using namespace boost::unit_test; class DataSet { public : DataSet( /* params */ ) { /* setup single data set */ } ~DataSet( ) { /* teardown single data set */ } /* some fields */ } class DataProvider { public : DataProvider() { dataSet.push_back( new DataSet( /* params */ ) ); /* add more if necessary */ } ~DataProvider() { /* free memory*/ } std::vector<DataSet*> dataSet; } 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 ); } However this is not correct since test cases created with BOOST_PARAM_TEST_CASE are not registered in the master test suite. If one of the tests fails I get the following log : Running 1 test case... ../test/functions/testSomeFunctions.cpp(67): error in "testMethod": check data->a == data->b failed [2 != 3] *** No errors detected I tried replacing "framework::run( test );" with "framework::master_test_suite().add( test );" but that doesn't work at all (log says that no errors were detected, while there should be one test that fails). I also tried something like this : BOOST_AUTO_TEST_CASE( ActivationFunctionTest ) { DataProvider dataProvider; framework::master_test_suite().add( BOOST_PARAM_TEST_CASE( &testMethod, dataProvider.dataSet.begin(), dataProvider.dataSet.end() ) ); } but the result is the same (No errors detected). What should I do? Jan

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
participants (2)
-
Gennadiy Rozental
-
JS