Testability
As already mentioned, another great advantage of using Dependency Injection is improved testability. We'll deep-dive into the topic of testing in Chapter 14, Testing Your Code with Unit and UI Tests, where we'll see in great detail how to exploit DI and the technique of Test Doubles to verify code that otherwise would have been impossible to test in an automatic way, such as an interaction with the user or with an external service. Here, it should be quite intuitive that as we can swap an implementation of a module with a different one with a different technology, we can also replace it with a fake one, a simplified version of the same module to have it under control while testing another component that depends on it.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access