Testing the Actual Interaction with Services
When working with third-party APIs like the weather API, we push the code that integrates with the API to the outside of our application in a lightweight wrapper. When we’re testing our application, we’re able to swap out that small part with a double to run the rest of our application. At some point, though, we also need to make sure that the code that talks to the API works. In this section, we’ll learn about the different approaches to do that.
In our weather API application, the code that talks to the weather API is this:
| defmodule SoggyWaffle.WeatherAPI do |
| @spec get_forecast(String.t()) :: |
| {:ok, map()} | {:error, reason :: term()} |
| ... |
Get Testing Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.