2

I am wondering whether Unit Testing is possible if I use a DB-First Entity Framework model -- or shall I rather do Integrity Tests only? Can I detach the system from the DB while testing?

I already have a context factory to have maximum one context per request. I could make the factory return an interface which could be instanciated as a wrapper of the EF context OR a fake testing implementation. So I would have to manually wrap the tables and stored functions of the generated EF context (including each changes), because it is not implementing anything... Man, that would be pain in everything and surely wouldn't worth it.

So what are your recommendations about Unit (or not Unit) Testing in this environment?

Update: I'm using EF 5

Gábor Imre
  • 5,899
  • 2
  • 35
  • 48

2 Answers2

3

You should take a look at this article where Julie Lerman answers to a similar question someone asked her on twitter. It will give you an overview of all the available testing techniques around EF.
Have a look at the article's comments as well where other interesting things are mentioned.

MaxSC
  • 4,698
  • 2
  • 23
  • 36
  • Thanks, I found lots of useful stuff here (and on blogs around this one) but not a direct solution for my question yet. (There is a very nice guide for EF4 though.) – Gábor Imre Aug 01 '13 at 12:10
  • 2
    The article has moved to [here](http://thedatafarm.com/data-access/whats-best-for-unit-testing-in-ef-it-depends-dude/) – SwampyFox Nov 01 '14 at 19:11
0

Take a look at The Repository Pattern.

dlebech
  • 1,817
  • 14
  • 27