Testing WebFlux controllers
So far, we've looked at unit testing as well as slice testing for MongoDB. These are good for covering services and backend logic. The last part we need to ensure is whether the web controllers are working properly.
Spring Boot comes with automated support to help us pick the exact type of test that we want to run. Let's start with an example:
@RunWith(SpringRunner.class) @WebFluxTest(controllers = HomeController.class) @Import({ThymeleafAutoConfiguration.class}) public class HomeControllerTests { @Autowired WebTestClient webClient; @MockBean ImageService imageService; ... }
This preceding beginning of a controller test case can be described as follows:
@RunWith(SpringRunner.class)
ensures all of our Spring Framework and Spring Boot test annotations integrate properly with JUnit.@WebFluxTest(controllers = HomeController.class)
is another slice of testing which focuses on Spring WebFlux. The default configuration...