How it works...

Similar to the previous recipe, Spring Boot test classes always start with a call to the @RunWith annotation with a SpringRunner parameter that tells JUnit to run all test cases within the context of the Spring TestContext framework. The SpringRunner parameter is a newer and shorter name for SpringJUnit4ClassRunner. The @SpringBootTest annotation, on the other hand, can be used to bootstrap the entire container in preparation for the integration testing. All beans are loaded into the Test framework to build MockMvc through the @AutoConfigureMockMvc annotation.

The unit test for request handler in Spring Boot 2.0 uses @WebMvcTest instead of @SpringBootTest, which is limited only to a single controller and can only execute with all the needed @MockBean annotation to provide mock implementations for the controller's required autowired beans. Mocking services and repository components are needed since not all beans are loaded into the Test framework.

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

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