How To: Use EntityFramework Core In-Memory Database For Unit Testing
Matheus Rodrigues Jun 7 Originally published at matheus.ro on Mar 19, 2018
You can download this article project on GitHub.
In this post, I’ll show how to use the in-memory feature of Entity Framework core to create unit tests involving the database. Let’s jump right in!
Create unit tests using a real DbContext is a pain because we have to mock the entire context to achieve this. Entity Framework core makes unit tests easier to write by providing us with an in-memory database provider. It creates an in-memory representation of our DbContext, for this reason, we don’t have to worry about mocking the database.