External Testing Strategy

Learn external services testing strategies with diagrams.

External services testing strategy

Our external-service testing story has two main characters:

  • The client, the part of our application code that uses the external API, either because it needs data accessible via the API or because it’s sending data to the API to be used by somebody else. In either case, we’re dealing with a request and a response, even if the response is just a status code.

  • The server, which for our purposes here is outside our application and reachable via some network request (though many of the strategies in this chapter also apply even if the network doesn’t separate the service).

We also introduce two characters to the story for design and testing purposes:

  • A fake server intercepts HTTP requests during a test and returns a canned response object. We’ll be using the VCR gem to manage our fake server (more about VCR shortly).

  • An adapter, an object that sits between the client and the server to mediate access between them.

External services testing diagram

The diagram that follows shows the relationship between these objects and the tests we’ll write using them.

Get hands-on with 1400+ tech skills courses.