Which statement is false about Web slice testing with @WebMvcTest?
- @WebMvcTest disables full auto-configuration
- @WebMvcTest auto-configure MockMvc bean
- @WebMvcTest does not auto-configure by default Spring Security
- Typically @WebMvcTest is used in combination with @MockBean for mocking dependencies
#spring #certificationquestion #vcp
By default, tests annotated with @WebMvcTest will also auto-configure Spring Security and MockMvc.
Testing Controllers With @WebMvcTest
When using the @WebMvcTest annotation approach with Spring Security,
MockMvc is automatically configured with the necessary filter chain required to test our security configuration.
Because MockMvc is configured for us, we’re able to use @WithMockUser for our tests without any additional configuration:
Note that using @WebMvcTest will tell Spring Boot to instantiate only the web layer and not the entire context.
Because of this, controller tests that use @WebMvcTest will run faster than with other approaches.