17 Unit testing EF Core applications
This chapter covers
- The three ways to simulate a database for unit testing
- Using the databases type as your production app for unit testing
- The pros and cons of using an SQLite in-memory database for unit testing
- Solving the problem of one database access breaking another part of your test
- Capturing logging information while unit testing
This chapter is about unit testing applications that use EF Core for database access. You’ll learn what unit-testing approaches are available when working with EF Core and how to choose the correct tools for your specific needs. I also describe numerous methods and techniques to make your unit testing both comprehensive and efficient. Personally, I think unit testing is very useful and I use it a lot. It makes me a better developer because I can catch bugs both while I’m developing the code and, more importantly, when I refactor the code.
But while I really like unit testing, I’m also very aware that writing unit tests takes development effort, including refactoring unit tests as the application grows. Over the years, I have learnt a lot of tips and techniques around unit testing and I have built a library called EfCore.TestSupport to help me, and you, to quickly and efficiently write unit tests.