I am in a process of writing unit tests for a project that uses EntityFramework Core and according to the docs I can use SQLite in-memory mode
or The InMemory provider
to approximate the database context.
The docs states that the SQLite in-memory mode
behaves like a relational database and that The InMemory provider
does not always behave like a relational database.
As far as I understand the SQLite mode sounds better because it behaves like relational database while the InMemory provider does not, but I guess there is other aspects to consider otherwise noone will use The InMemory provider
which sounds a lot worse.
Is there other pros and cons to each approach I should consider before I choose which tool to use?
While some users use the in-memory database for testing, this is generally discouraged; the SQLite provider in in-memory mode is a more appropriate test replacement for relational databases.
Keep using EF6 if the data access code is stable and not likely to evolve or need new features. Port to EF Core if the data access code is evolving or if the app needs new features only available in EF Core. Porting to EF Core is also often done for performance.
Testing EF Core Applications Testing is an important concern to almost all application types - it allows you to be sure your application works correctly, and makes it instantly known if its behavior regresses in the future.
If your sole purpose is writing Unit Tests, look closely at the boiler plate code needed to create the tests, that could impact your deadlines... I would go with the option that makes me type less code! (The InMemory provider
looks simpler).
Look at the samples and decide:
...and of course your project will have Integration Tests, on those you will connect to the real database and do additional checks. That's why for the unit tests my main concern is writing time, not so much how the mock DB behaves
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With