Use the current class as the base class for your appliances:
class TheClassTestBase : public ::testing::Test { protected: TheClassTestBase(std::string filename) : datafile(filename) {} ... };
For each specific file name, use a derived device:
class TheClassTestForFooTxt : public TheClassTestBase { protected: TheClassTestForFooTxt() : TheClassTestBase ("foo.txt") {} };
However, this is an additional step necessary for each set of parameters, so you can try using templates or macros to do this with less effort. How:
template <typename ClassTestTag> struct ClassTestParams { static std::string filename; }; template<typename ClassTestTag> class TheClassTest : public TheClassTestBase { protected: TheClassTest() : TheClassTestBase (ClassTestParams<ClassTestTag>::filename) {} };
Then - for each set of parameters - do the following:
class FooTxtTag {}; template <> std::string ClassTestParams<FooTxtTag>::value = "foo.txt"; using TheClassTestForFooTxt = TheClassTest<FooTxtTag>; TEST_F(TheClassTestForFooTxt, xxxx) {}
However - in your particular case - I would also try GoogleTest: type-parameterized-tests .
source share