Before migrating to Spring Boot 2.1, we had a couple of controller tests in our services utilizing @WebMvcTest
in combination with @AutoConfigureMockMvc
Encountered the same scenario and what helped was using the below annotations instead of @WebMvcTest
. In this case, @WithMockUser
did not help.
@WebAppConfiguration
@Import({MockMvcAutoConfiguration.class})
@EnableConfigurationProperties({ResourceProperties.class, WebMvcProperties.class})
Classes that existed in controllers
/ value
of @WebMvcTest
goes into value
of @Import
annotation.
Source: https://github.com/spring-projects/spring-boot/issues/14227#issuecomment-688824627