External Dependencies and Their Challenges
Understand the challenges external dependencies bring to unit testing, especially when tightly coupled. Learn how to use dependency injection and mocks to create loosely coupled classes that enable reliable and controlled unit tests. This lesson helps you manage dependencies effectively to write maintainable and testable code.
Introduction
A dependency is a class or object that another class or object relies on. In object-oriented languages, the application code consists of classes where some classes rely on other classes. In this context, relying means that one class is referenced in the other class code. It could be included in any of its method parameters, its method return types, or even in any of its method implementations. This concept is shown below where Class A depends on Class B. In this context, Class B is a ...