This question already has an answer here:
- Databases and Unit/Integration Testing 6 answers
Suppose I have component
C that all put some data into a database. Each component depends on data in the database inserted by the previous component.
How do I test these modules in isolation? I already have tests at the unit level, but I now want to test with the database. I have seen suggestions to make a dump of the database for each step, but this is a messy thing to check in to version control and requires a lot of effort whenever the architecture changes (which where I work translates to "abandon tests!").
I really think that the best approach is to clear my test database before running tests and use some tool to specify test dependencies to ensure correct running order, but this seems to be seriously frowned upon by the opinions I've read. To me it seems the same as using a fixture for each step, except that the fixture is just a cheap way of hiding the dependency.