Test with MockWebServer
Explore how to implement non-blocking REST client calls with Spring WebClient and verify them using MockWebServer. Learn to set up a local mock server, enqueue responses, and run unit tests to ensure your service behaves as expected when accessing third-party APIs.
We'll cover the following...
We'll cover the following...
The WebClient class
Spring recommends using the WebClient class instead of RestTemplate for accessing the third-party APIs, because WebClient provides a non-blocking reactive client over the underlying HTTP client.
Setup
First, let’s add Spring Boot’s spring-boot-starter-webflux dependency, which incorporates the WebClient ...