Last post Mar 29, 2010 05:17 AM by TATWORTH
Mar 03, 2010 04:23 PM|X-Rider|LINK
Does anyone knows how to isolate the database for the tests as in unit testing?
For example my tests are deleting records from the database. I would like to isolate my database in each test a transaction otherwise I will have to deploy a new database each time I want to run my tests...
Mar 04, 2010 07:49 AM|Aquaren|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.
Mar 13, 2010 12:27 PM|X-Rider|LINK
I use the repository pattern in my application. I run the tests against a dev database, but if I want my tests to run isolated (add, edit and delete tests), would be good to define a transaction and rollback in the end of each test.
Mar 15, 2010 08:05 AM|Aquaren|LINK
The problem with that approach is you won't actually know if the data has be successfully stored. The steps should be as follows:
Insert a new record
Select that record and create a sanity assert to assure an object was returned
Delete the record
Select the record again and create a sanity assert to assure a null was returned
Mar 29, 2010 05:17 AM|TATWORTH|LINK
Why not create create a second development database, in which you run a script to drop all objects, then run a script to create all objects, before running your battery of database tests?
This is an an approach that I seen successfully used on several projects.