VMware vRealize Automation 8.x (2022) — Question 51
Which option is true about use of mocks in a Spring Boot web slice test? (Choose the best answer.)
Answer options
- A. Mocking a Spring Bean requires annotating it with @MockBean annotation.
- B. If a Spring Bean already exists in the web slice test spring context, it cannot be mocked.
- C. Mocks cannot be used in a Spring Boot web slice test.
- D. Mocking a Spring Bean requires annotating it with @Mock annotation.
Correct answer: A
Explanation
The correct answer is A because the @MockBean annotation is specifically designed for replacing beans in the Spring context with mock instances during testing. Option B is incorrect as existing beans can be mocked with the right annotations. Options C and D are also wrong; mocks can be used in tests, but @Mock alone does not integrate with the Spring context like @MockBean does.