0Pricing
Testing Mastery: JUnit, Mockito & Integration Tests · Lesson

Testing Web Layers with @WebMvcTest and MockMvc

Slice-test Spring Boot controllers in isolation using @WebMvcTest and MockMvc without starting the full application context.

Why Slice Tests?

Loading the entire Spring context for every controller test is slow. Spring Boot offers test slices that load only the beans you need. @WebMvcTest loads just the web layer.

What @WebMvcTest Loads

@WebMvcTest configures controllers, filters, and JSON converters, but not services or repositories. Those collaborators are supplied as mocks.

All lessons in this course

  1. Spring Test Context Framework
  2. Testing RESTful APIs
  3. Embedded Databases for Tests
  4. Testing Web Layers with @WebMvcTest and MockMvc
← Back to Testing Mastery: JUnit, Mockito & Integration Tests