If you cannot run your unit tests without a database, then you need to take a look at your architecture. You need some abstraction (like the
Repository pattern). Then create a new set of integration tests for testing against the actual database. Part of that testing should involve a dev database that does not get deployed so data corruption is less of an issue. Also, as part of your tests, to
setup the data environment such that when the tests are complete, the database is in basically the same state is was before you ran the tests.
So, for example, as part of your delete tests, insert a record first then delete that record.
Aquaren
Contributor
2360 Points
421 Posts
Re: isolating database in tests
Mar 04, 2010 11:49 AM|LINK
If you cannot run your unit tests without a database, then you need to take a look at your architecture. You need some abstraction (like the Repository pattern). Then create a new set of integration tests for testing against the actual database. Part of that testing should involve a dev database that does not get deployed so data corruption is less of an issue. Also, as part of your tests, to setup the data environment such that when the tests are complete, the database is in basically the same state is was before you ran the tests.
So, for example, as part of your delete tests, insert a record first then delete that record.