0

This is the 2nd part of another question Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable), where I asked how to implement a generic repository pattern using EF 4 POCO. Now that my repository is working, I would like to know how to unit test my Repository (TDD or BDD).

Thanks all.

Community
  • 1
  • 1
Saxman
  • 5,009
  • 11
  • 51
  • 72
  • I test with XUnit and use the AutoRollback feature. I don't know if NUnit has this feature, but you can google for it. That way you can do integration tests on your repos that will alter your database, then roll back the changes. – Paul Jan 25 '11 at 00:57
  • Thanks Paul, I'll check to see if NUnit have that feature or not. – Saxman Jan 25 '11 at 15:51
  • Did you find something similar to AutoRollback in NUnit? – Brendan Vogt Feb 17 '11 at 06:06
  • I didn't use the AutoRollBack feature. I have an Initializer class that override the "Seed" method and seed/restore the data whenever I need a fresh copy of the data :) – Saxman Feb 17 '11 at 15:45

1 Answers1

0

Hey I wrote some blog posts on doing this with SpecFlow. But that was a disaster when it got complex.

I tried to implement a testing repository which was also a disaster. Trying to replicate how the data context work is not a smart idea.

But you learn from your mistakes and have fun along the way. What I learnt was to use a light-weight or in-memory database (SQLite).

So I would definitely say to use a SQLite database if you can get it working with EF Code First. I wasn't able to do this, so I went with a SQL CE compact edition. It runs amazingly quick, even in testing.

You probably know all about this blog post, but re-check step 4. http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

So in essence, all I did on my most recent project was to have a separate database SQL CE 4.0 compact edition for testing. Super quick and no complaints.

nick
  • 1,477
  • 2
  • 20
  • 29
  • Thanks Nick... I guess I can work directly with the database since I'm using SQL CE for testing purposes anyway. – Saxman Jan 25 '11 at 15:50