Entity Framework (code first) in memory database for unit testing

Viewed 2496

For unit testing purposes, is it possible to do this:

  • Have test data in some format (XML?) checked into source control
  • When unit tests are run, instantiate some kind of in memory database from this test data
  • Have EF run against this in memory database for the duration of the unit test run

?

We don't want our unit tests to rely on a specific external database being present, and in a specific state.

We also don't want to maintain two different "worlds" in our code and tests, the real world where EF runs against a real db and a fake work where our tests run against some kind of EF mock.

1 Answers
Related