Which option is true about use of mocks in a Spring Boot web slice test? (Choose the best answer.)

Which option is true about use of mocks in a Spring Boot web slice test? (Choose the best answer.)
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.

Answer: A

Explanation:

A web slice test is a type of test in Spring Boot that focuses on testing only the web layer of an application, without starting a full server or requiring a real database. To isolate the web layer from other dependencies, such as services or repositories, mocks can be used to simulate their behavior and return predefined responses. To create and inject a mock for an existing bean in the application context, the @MockBean annotation can be used on a field or a parameter in the test class. This annotation will replace any existing bean of the same type with a mock created by Mockito.

Reference: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.testing.spring-boot-applications.testing-autoconfigured-web-test: https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/mock/mockito/MockBean.html:

https://site.mockito.org/

Reference: https://tanzu.vmware.com/developer/guides/spring-boot-testing/

Latest 2V0-72.22 Dumps Valid Version with 60 Q&As

Latest And Valid Q&A | Instant Download | Once Fail, Full Refund

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments