20 June 2006

Testing Data Access Layers (DALs)

It seems that testing DALs is harder than I thought. One of the problems I have run into is how to preserve DB integrity. Some of the alternatives are:

  1. Create mock objects that replace the database.
  2. Have a separate DB for testing.
  3. Restore the DB on every test run.
  4. Run the test inside transactions and then rollback.
Another concern is: How the tests must be designed in order for their success or failure to depend only on the coding and not on the data state?

Related Links

Testing Frameworks:

Unit Testing in .Net Proyects
by Jay Flowers

Transaction approach:

Simplify Data Layer Unit Testing using Enterprise Services
Alternative Testing Frameworks

Mock Objects:

Mock Objects to the Rescue! Test your .NET code with NMock
Mocks Aren't Stubs by Martin Fowler

Testing sequences (useful for CRUD operations):

Advanced Unit Testing, Part III - Testing Processes by Marc Clifton