Cloud Native Spring: Testing and Documentation

In this session, we'll see how to define contracts for microservice APIs using Spring Cloud Contract that can assist in testing clients of those services. Additionally, we'll look at Spring RestDocs, a project that provides semi-automatic production of API documentation.

Microservice-architecture presents many benefits, not the least of which include opportunities to develop, evolve, scale, test, and deploy individual modules of an application independently from the rest of the application. But once an application is broken apart, a new set of challenges arises.

Testing microservices, particularly when testing the code in one service that invokes another, can be challenging. It involves writing tests that mock out the remote service. But since it they target a remote service whose code is separate, those mocks may fall out of sync with changes in the service that they mock. Rather than manually write mocks against our own understanding of an API, it would be better to define a contract that both the remote API and the mock agree upon. And for testing purposes, mocks can be generated from that contract.

When it comes to documenting microservice APIs, you have a few choices: You can either fully automate documentation, based on the implementation code, or you can manually document the API. The former creates a tight-coupling between the documentation and the code, which makes the documentation fragile when the code changes. The latter requires much more effort, both in the initial creation as well as in keeping it in sync with API changes. But what if there were a middle-ground, a semi-automatic way to document an API?


About Craig Walls

Craig Walls is a Principal Engineer, Java Champion, Alexa Champion, and the author of Spring AI in Action, Spring in Action, and Build Talking Apps. He's a zealous promoter of the Spring Framework, speaking frequently at local user groups and conferences and writing about Spring. When he's not slinging code, Craig is planning his next trip to Disney World or Disneyland and spending as much time as he can with his wife, two daughters, 1 bird and 2 dogs.

More About Craig »