Boost logo

Boost :

Subject: Re: [boost] [test] Automatic registration of tests created with BOOST_PARAM_TEST_CASE
From: Jan Stolarek (fremenzone_at_[hidden])
Date: 2009-05-10 03:22:52


Ok, I figured out a solution that seems to be quite elegant, not so verbose
and easy to achieve :

using namespace boost::unit_test;

class DataSet {
  public :
    DataSet( /* params */ ) { /* setup single data set */ }
    ~DataSet( ) { /* teardown single data set */ }
    /* some fields */
}

void testMethod( DataSet* data ) {
  /* do something with method that's being tested. Use data somehow */
  BOOST_CHECK( /* assertion */ );
}

BOOST_AUTO_TEST_CASE( TestNameFirstDataSet ) {
  DataSet dataSet( /* params for first data set */ );
  
  testMethod( dataSet );
}

BOOST_AUTO_TEST_CASE( TestNameSecondDataSet ) {
  DataSet dataSet( /* params for second data set */ );
  
  testMethod( dataSet );
}

It's so simple that I wonder why didn't I figure it out right away. It doesn't
require extra lines of code (dataSet has to be created somewhere anyway), it
even allows to get rid of DataProvider class. Also there is no problem of
spliting the tests into many files (I think this could be problematic if I
had used global fixture, since all the data sets would have to be defined in
one file). Any bad sides of this approach?

Jan


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