Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Entity Framework 5 - Is in memory database a good option

I appreciate that there is already a lot entity framework testing questions here. However, I came across Effort, which allows an in memory version of the database context. I guess I have a few questions around this area:

  1. What are the pros and cons of using such a method?

  2. I think EF and the in memory database use a repository and unit of work pattern, so does that mean that we don't implement our own when using this method?

  3. There are other options like providing a fake IDBSet, using SQL CE or implementing a repository and unit of work pattern, Am I better using one of these techniques?

I feel a little bit overwhelmed with the amount of choice here. I realize that there is probably not a silver bullet but am hoping for some guidance please.

Thanks

like image 205
davy Avatar asked Nov 12 '22 04:11

davy


1 Answers

1) pro: you can test that your DAL function actually work, you dont spend ages mocking repositories, provided you instance it you can run tests faster (hours on large projects). con:you are not actually testing your actual db - defeats the point of integration testing. Also changing databases is a config string. Edit later: I used to unit test a ton, i tend to prefer vertical slices now. I find that by the time i care about the database i am at the point where i need an integration test anyway.

Personally i am a fan of end to end testing as it keeps the tests focused - reduces the number and actually tests against a specification.

2) uow and repository pattern facilitate different things. The repository encapsulates the DAL and should abstract away from the db provider itself - usually through a unit of work pattern. The unit of work essentially gives you transactional access and should give you the hook through which you use your in memory db when testing. So i personally don't feel like they are useless. When you want to test and mock out your dal (say for a small unit test rather than acceptance / integration) the repro pattern will pay for itself. Could you get away without it? probably but the cost of having it is tiny and also makes everything be neat and ordered. Besides as hinted above when i eventually get around to needing to implement the db i do want an integration test - i find these can easily be implemented from ui level because i have already worked / tested in from the outside.

3) dunno that is not something anyone can answer for you. Play with them.

like image 141
John Nicholas Avatar answered Nov 14 '22 22:11

John Nicholas