6.1. Problem

Other than standard ASP.NET tables, we have not touched the database or created any tables. I deliberately wanted to delay doing anything with the database until we needed to, and so far we haven't. Dealing with databases can complicate testing. We have to worry about managing data and maintaining the state of the database during testing. We also have to restore the database to a neutral state after each test. You can see how this could complicate our testing and also considerably slow it down. If your tests are too slow, you will run them less often, you will be less likely to write them, and you will very quickly lose interest in Test Driven Development.

We need to abstract the data layer so that we can run our tests without ever touching the database. We also want to be able to run our website and have it function without needing to create or populate the database with anything. We basically want to be able to use an in-memory database but at the same be able to easily switch to using the real database without re-writing any code.

Get ASP.NET MVC 1.0 Test Driven Development: Problem - Design - Solution now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.