Dependency Doubles
Learn how to deal with external services in integration testing.
Terminology
The component that acts as the external dependency is often called a double of that dependency.
The name comes from the fact that the dependency double looks exactly like the dependency to the callers of the dependency. The implementations of dependency doubles can vary in complexity:
- A dependency double looks exactly like the external dependency but doesn’t do anything.
- The dependency double can be used to gain insight into how the dependency is called and possibly test the interaction.
Let’s dive into how we can use dependency doubles in our Soggy Waffle application.
Using a dependency double in Soggy Waffle
Soggy Waffle needs to interact with a weather API (through HTTP) to fetch the weather forecast periodically. The weather API is an external component to our application, so it’s a good design to isolate our interactions with it into a module ...