Search⌘ K
AI Features

Introduction to @WebMvcTest

Explore how to apply the @WebMvcTest annotation to test Spring Boot web controllers without starting the full application. Understand the components that are loaded by default, how to handle required dependencies, and why this approach is favored over plain unit testing for controllers. Gain skills to perform focused integration tests on the web layer with MockMvc.

Testing in Spring Boot

Spring Boot offers various utilities to start an application for testing, either fully or partially. We can use @SpringBootTest as a class annotation for a JUnit test which will start our complete application, including an embedded Tomcat to serve the HTML pages.

However, for tests that will only test a controller for example, we don’t need to start the full application.

Spring Boot has test slices that allows us to start, say, only the database layer ( ...