Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automated integration testing a C++ app with a database

I am introducing automated integration testing to a mature application that until now has only been manually tested.

The app is Windows based and talks to a MySQL database.

What is the best way (including details of any tools recommended) to keep tests independent of each other in terms of the database transactions that will occur?

(Modifications to the app source for this particular purpose are not an option.)

like image 436
Peter Avatar asked Sep 17 '08 20:09

Peter


3 Answers

How are you verifying the results?

If you need to query the DB (and it sounds like you probably do) for results then I agree with Kris K, except I would endeavor to rebuild the DB after every test case, not just every suite.

This helps avoid dangerous interacting tests

As for tools, I would recommend CppUnit. You aren't really doing unit tests, but it shouldn't matter as the xUnit framework should give you the set up and teardown framework you'll need to automatically set up your test fixture

Obviously this can result in slow-running tests, depending on your database size, population etc. You may be able to attach/detach databases rather than dropping/rebuilding.

If you're interested in further research, check out XUnit Test Patterns. It's a fine book and a good website for this kind of thing.

And thanks for automating :)

Nick

like image 195
Nick Monkman Avatar answered Oct 18 '22 21:10

Nick Monkman


You can dump/restore the database for each test suite, etc. Since you are automating this, it may be something in the setup/teardown functionality.

like image 34
Kris Kumler Avatar answered Oct 18 '22 21:10

Kris Kumler


I used to restore the database in the SetUp function of the database related unit test class. This way it was ensured that each test runs under the same conditions.

You may consider to prepare special database content for the tests, i.e. with less data than the current production version (to keep the restore times reasonable).

like image 26
Fabian Avatar answered Oct 18 '22 21:10

Fabian