Bird
0
0

What is the main purpose of using @WebMvcTest in Spring Boot testing?

easy📝 Conceptual Q11 of 15
Spring Boot - Testing Spring Boot Applications
What is the main purpose of using @WebMvcTest in Spring Boot testing?
ATo test only the web layer (controllers) without starting the full application context
BTo test the entire Spring Boot application including database and services
CTo perform integration testing with real HTTP calls
DTo test only the service layer without controllers
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of @WebMvcTest

    @WebMvcTest is designed to load only the Spring MVC components like controllers, filters, and related configurations, not the full app context.
  2. Step 2: Compare with other test annotations

    Unlike @SpringBootTest which loads the full context, @WebMvcTest focuses on controller layer for fast, isolated web tests.
  3. Final Answer:

    To test only the web layer (controllers) without starting the full application context -> Option A
  4. Quick Check:

    @WebMvcTest = controller-only test [OK]
Quick Trick: Remember @WebMvcTest loads only controllers, not full app [OK]
Common Mistakes:
  • Thinking @WebMvcTest loads full Spring context
  • Confusing @WebMvcTest with @SpringBootTest
  • Assuming it tests service or repository layers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes