15 Unit testing EF Core applications
This chapter covers
- Simulating a database for unit testing
- Using an in-memory database for unit testing
- Using real databases for unit testing
- Unit testing a disconnected state update
- 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 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.
Unit testing is a big subject, with whole books dedicated to the topic. I focus on the narrow, but important, area of unit-testing applications that use EF Core for database accesses. To make this chapter focused, I don’t explain the basics of unit testing, but leap right in. I therefore recommend anyone new to unit testing to skip this chapter, or come back to it after you’ve read up on the subject. This chapter won’t make any sense without that background, and I don’t want to discourage you from unit testing because I make it look too hard.
Tip
To learn more about unit testing, have a look at https://msdn.microsoft.com/en-us/library/hh694602.aspx. For much more in-depth coverage of unit testing, I recommend Roy Osherove’s The Art of Unit Testing: with Examples in C#, Second Edition (Manning, 2013), http://mng.bz/1f92.