Depending on the kind of project you’re working on, you may feel that you spend more time writing tests than code. As the code you test gets more complex in terms of relationships and dependencies on other code, the tests also become more complex. Code built on a SOLID foundation (pun intended) can take advantage of certain techniques and libraries to help make tests easier to write. This chapter contains a set of commonly used techniques that help make testing easier.
The units in chapter 6 have simple relationships. For more complex code, a unit may depend on several other units, which is true of many ASP.NET Core components. ASP.NET Core has built-in dependency injection and implements the dependency inversion principle. In testing situations, dependencies can be replaced by mocks or fakes that are designed to do nothing except return specific values if needed.