Skip to main content

@WebMvcTest

Learn @WebMvcTest (Spring MVC Testing, Spring MVC) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Fresher Notes @WebMvcTest is a test slice annotation that starts only the web layer (controllers, advice, filters, converters) and not services or repositories. MockMvc is auto-configured and injected with @Autowired ; you call mockMvc.perform(get("/x")) without a real server or port. Collaborators such as services are replaced with @MockBean (or @MockitoBean in newer Spring), so the test checks only the controller.

More lessons in Spring MVC Testing