I want to write a parametrised unit test using boost::test. Preferably I'd like to pass parameters to my fixture class. I write multiple test cases with the same setup and tear-down scenarios, so it'd be pretty handy. Unfortunately, I'm aware that the boost::test framework assumes that the fixture class has a zero-constructor. So I can't see any way to pass the test parameter inside the fixture class.
Do you have any idea how could I properly design my test?
My only guess is to use BOOST_DATA_TEST_CASE_F
and call some helper method inside a test body. More or less something like this:
struct Fixture
{
Fixture( void )
{
// initialise 'zombie' fixture
}
void set_up( int parameter )
{
// common init with parameter
// fixture is fully functional now
}
};
BOOST_DATA_TEST_CASE_F(
Fixture,
DummyTest,
boost::unit_test::data::make<int>( { 1,2,3 } )
)
{
set_up( sample ); // `sample` variable is provided by boost::test
BOOST_TEST(true);
}
However, I don't like the idea of adding the set_up
method at the beginning of each test. Maybe in boost, there's some hidden feature that I could re-use in this case?