When unit testing Spring Boot applications, how can you mock the behavior of methods in a class?
- Using Spring's @MockBean annotation
- Using the @Autowired annotation
- Using the @InjectMocks annotation
- By directly modifying the source code
In Spring Boot, you can mock the behavior of methods in a class using the @MockBean annotation from the Spring Test framework. This annotation creates a mock of the specified class or interface, allowing you to define the behavior of its methods in your test. The other options are not the standard way to mock methods in Spring Boot unit tests.
Loading...
Related Quiz
- In Spring Boot, the _____ annotation can be used to specify the conditions or actions that should be executed before testing each method.
- In a Spring Boot application, the _____ is a test utility used for making HTTP requests to the application and can be auto-configured in integration tests.
- In Spring Security, what is the significance of configuring a global method security, and how does it differ from standard method security configurations?
- The @DataJpaTest annotation in Spring Boot is typically used to test _____.
- Custom Auto Configurations are usually defined in a separate _____ to avoid being included by component scanning.