Adding automated microservice tests in isolation

Before we wrap up the implementation, we also need to write some automated tests.

We don't have much business logic to test at this time, so we don't need to write any unit tests. Instead, we will focus on testing the APIs that our microservices expose; that is, we will start them up in integration tests with their embedded web server and then use a test client to perform HTTP requests and validate the responses. With Spring WebFlux came a new test client, WebTestClient, that provides a fluent API for making a request and then applying assertions on its result.

The following is an example where we test the composite product API by doing the following:

  • Sending in productId for an existing product ...

Get Hands-On Microservices with Spring Boot and Spring Cloud 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.