2V0-72.22PSE · Question #90
Which two statements are true regarding @WebMvcTest? (Choose two.)
The correct answer is A. It auto-configures a MockMvc. D. Typically it is used in combination with @MockBean when there is a dependency bean to be. @WebMvcTest auto-configures MockMvc (A) so you can test controllers by simulating HTTP requests without starting a real server - making C wrong, since it explicitly tests without a running server. Because @WebMvcTest only loads the web layer (controllers, filters, etc.) and not…
Question
Which two statements are true regarding @WebMvcTest? (Choose two.)
Options
- AIt auto-configures a MockMvc.
- BIt will only scan for @Controller beans in the source code.
- CIt is used for testing Spring MVC components such as @Controller with a running server.
- DTypically it is used in combination with @MockBean when there is a dependency bean to be
- EIt is typically used with @ExtendWith(MockitoExtension.class) in JUnit 5.
How the community answered
(56 responses)- A89% (50)
- B2% (1)
- C4% (2)
- E5% (3)
Explanation
@WebMvcTest auto-configures MockMvc (A) so you can test controllers by simulating HTTP requests without starting a real server - making C wrong, since it explicitly tests without a running server. Because @WebMvcTest only loads the web layer (controllers, filters, etc.) and not the full application context, any service or repository dependencies won't be present, so you must declare them with @MockBean (D) to satisfy the controller's dependencies. B is wrong because @WebMvcTest scans more than just @Controller - it also picks up @ControllerAdvice, @JsonComponent, Filter, WebMvcConfigurer, and similar web-layer beans. E is wrong because @WebMvcTest already includes @ExtendWith(SpringExtension.class) as a meta-annotation; using MockitoExtension instead would bypass the Spring test context entirely.
Memory tip: Think of @WebMvcTest as a "web slice only" test - it gives you MockMvc automatically (A) and forces you to MockBean everything else (D). Both A and D have "Mock" in them.
Topics
Community Discussion
No community discussion yet for this question.