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.