API Integration Tests

WebDriver tests are useful and often form part of a well designed test strategy. They can though be slow and sometimes fragile (dependent on particular browsers, drivers, OSes, etc.) which naturally increases the maintenance overhead.

When working in the world of Spring Boot and REST APIs, I’ve found that there is a sweet spot for favouring API integration tests, often ahead of unit tests. When unit testing a REST Controller, you’ll need to be heavy on mocking and all you can really test is the interaction with the mocks. This is testing the implementation of the controller, rather than the behaviour.

An API Integration test lets you test that:

  • Your application context can start up successfully
  • Your application can talk over-the-wire to its dependencies (which are mocked with Restito or similar)
  • You can test the output of the Controller (including response codes etc)
  • All running in the same process - quite a decent ROI.

An example of an API Integration Test can be found in Browse: com.johnlewis.web.app.fabric.FabricControllerFunctionalTest

This runs the Browse app against an in-process instance of Restito (acting as the BFF).