Which method is used to verify that a method was called on a mock object in Mockito?

Which method is used to verify that a method was called on a mock object in Mockito?

A) verify()
B) assert()
C) check()
D) validate()

Answer:

A) verify()

Explanation:

In Mockito, the verify() method is used to check that a particular method was called on a mock object during the test. This is important for ensuring that the code behaves as expected and interacts with its dependencies correctly.

For example:


verify(mockObject).someMethod();

In this example, verify() checks that the someMethod() was called on the mockObject. If the method was not called, the test will fail, indicating that the expected interaction did not occur.

Reference links:

https://www.javaguides.net/p/mockito-tutorial.html

Leave a Comment

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

Scroll to Top