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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.