Spring Boot 4 · Actuator and testing

Test a controller

Load only the web layer and call it with MockMvc.

@WebMvcTest(UserController.class)
class UserControllerTest {

    @Autowired MockMvc mvc;

    @Test
    void returnsUser() throws Exception {
        mvc.perform(get("/api/users/1")).andExpect(status().isOk());
    }
}

Official Spring Boot 4 documentation

More actuator and testing commands

All actuator and testing commands · Spring Boot 4 cheatsheet

Was this page helpful?