In the starting of the test class, we have added the @RunWith(SpringRunner.class). This tells JUnit to run using Spring’s testing support.
we have also used @WebFluxTest(EmployeeController.class). Using this annotation will disable full auto-configuration and instead apply only configuration relevant to WebFlux tests (i.e. @Controller, @ControllerAdvice, @JsonComponent, Converter/GenericConverter, and WebFluxConfigurer beans but not @Component, @Service or @Repository beans). Typically @WebFluxTest is used in combination with @MockBean or @Import to create any collaborators required by your @Controller beans.
Inside our test class, we have our webTestClient Object. It is a non-blocking, reactive client for testing web servers. It uses reactive WebClient internally to perform requests and provides a fluent API to verify responses. WebTestClient can connect to any server over an HTTP connection. It can also bind directly to WebFlux applications using mock request and response objects, without the need for an HTTP server.
We have used @MockBean annotation with EmployeeService. When @MockBean is used on a field, as well as being registered in the application context, the mock will also be injected into the field.
With WebTestClient we can define the route and its expected response in the test case. The assertions can be done using expectStatus(), expectHeader() or even expectBody(). How to use them is already given in the code above.
https://blog.knoldus.com/spring-webflux-how-to-test-your-controllers-using-webtestclient/