We’re developing in C++ under Linux and about to set up automated tests. We intend to use a testing framework like CppUnit oder CxxTest. We’re using Ant to build the software and we will also use it to run the tests.
As some tests are going to involve database access, we are looking for a tool or framework which facilitates the tasks of preparing and cleaning up test data in the database – just like DbUnit (a JUnit extension) in the Java world.
Another option may be to employ the actual DbUnit – a Java VM is available. Making use of DbUnit’s Ant task seems to be most promising. Any related field reports are welcome!
As there seems to be no DbUnit-like tool for C++ development, we’ve built a little framework of our own. Basically it’s an adaptor for calling actual DbUnit operations from within C/C++ testrunners. It makes use of the Ant tasks provided by DbUnit.
We defined some macros like
TS_DB_INSERT(filename)which callsystem('ant -Ddb.dataset=filename db.insert')and the like.In this case,
db.insertis an Ant target which executes a DbUnit task performing an INSERT operation on the database. Thefilenamereferences an XML dataset containing the data to insert. There’s also an assertion macro which wraps a DbUnitcompare.The test case might look like this: