Search⌘ K
AI Features

Test The Controller With @WebMvcTest

Explore how to use the @WebMvcTest annotation to unit test Spring MVC controllers by mocking service layers with @MockBean. Learn to inject MockMvc for simulating web requests and verify JSON responses for REST endpoints in TodoController and TodoTypeController.

We can use the @WebMvcTest annotation to test the controller layer, in a similar way to how we used @DataJpaTest for JPA tests.

The TodoControllerTest class

Let’s create the TodoControllerTest class in the io.educative.unit ...