I have had a discussion with someone about unit/integration testing with web applications and I have a disagreement about 1 core idea. The issues is that the person I am talking to think that the database the unit test work off of should have pre-populated data in it and I think it should be completely empty before and after the tests are executed.
My concern with pre-populated data in the database is that there is no way to make sure that data is maintained in a good state. The tests themselves are going to be creating, deleting, and modifying data in the database so I really don't see how having data in the database before you start the tests is a good thing.
Is seems the the best way of testing database functionality would be having the following setups:
- In a "setup" phase before the test actually run, you first truncate all the tables in the database
- Then you insert all the data needed for the test cases you are about to run
- Then you run and validate the test cases
- Then in a "teardown" phase you once again truncates all the tables in the database
I don't see any other better way to ensuring that the data you are testing against in is a good testable test.
Am I missing something here? Is this not the best way to test database related functionality? Is there some benefit to have pre-populated database that always exists in the database (even before you start the tests or after the tests are done)? Any help in ideas to explain my process differently to better get my point across would also be great (that is if my point has merits).