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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *