Hi,
I am trying to create tests for database plugins for my library.
I have 3 plugins. Every one of them is tested using the same tests cases.
I want to create one main suite, that is responsible for plugin initialization
and creation of database schema for tests.
I want to add arbitrary number of test cases (derived from CppUnit::TestCase)
to the main suite and run it. Every test case needs to know handle to
database plugin and connection parameters, which are owned by main suite.
So far I created following structure:
//main test suite
class DbPluginTestSuite : public CppUnit::TestSuite {
void init();
Database* mDb;
const char* mConnParams;
};
//base class for test cases
class Db_TestBase : public CppUnit::TestCase {
public:
void setParams(Database* pDb, const char* pConnParams);
protected:
Database* mDb;
const char* mConnParams;
};
//example test case
class Db_Basic : public Db_TestBase {
CPPUNIT_TEST_SUITE()
CPPUNIT_TEST(someTest)
CPPUNIT_TEST_SUITE_END();
public:
void someTest() //uses mDb and mConnParams from parent class
};
I am trying to run tests like this:
CppUnit::TextTestRunner runner;
DbPluginTestSuite* mainSuite = new DbPluginTestSuite();
mainSuite->init();
Db_testBase* tc = new Db_Basic();
tc->setParams(mainSuite->mDb,mainSuite->mConnParams)
mainSuite ->addTest(tc); //BAD
runner.addTest(mainSuite);
Line marked BAD causes tc to be added to suite, but only first test is called.
I cannot use Db_Basic::suite(), because this method creates new uninitialized
object.
I think that I need to create TestSuite using existing TestCase pointer (tc)
and pass it to mainSuite->addTest().
Is there any way to do it?
Thanks for help,
Łukasz
|