Reactive WebTestClient

Similar to WebClient, Spring WebFlux provides you with a non-blocking, reactive client named WebTestClient, to test your reactive APIs on your server. It has utilities that make testing these APIs easily in a test environment setup. WebTestClient can connect to any of the servers, as detailed earlier over an HTTP connection and execute necessary tests. However, the client has the capability of running the tests with and without a running server.

WebTestClient also has a number of utilities to verify the response produced by executing these server side APIs. It can quite easily bind itself to the WebFlux web application and mock necessary request and response objects to ascertain the API's functional aspects. WebTestClient can mutate the headers as needed, to simulate the desired test environment. You can get an instance of WebTestClient for your entire application (by using the WebTestClient.bindToApplicationContext method), or you can restrict it to specific controller (using the WebTextClient.bindToController method), RouterFunction (using the WebTestClient.bindToRouterFunction method), and so on.

We will see a detailed example of how WebTestClient works in a subsequent hands-on section (The Sample project section, under the Testing (WebTestClient) sub-section).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.241.48