|
Boost : |
Subject: [boost] [test] Automatic registration of tests created with BOOST_PARAM_TEST_CASE
From: JS (fremenzone_at_[hidden])
Date: 2009-05-07 08:00:55
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk