Skip to content
Sharp

Project Structure · interview question

When using Mockito, how can you verify that a method was called a specific number of times on a mock object?

Multiple choiceHardchapter-10-curatedpremiumproject-structurecontinuous-integration
Choose one answer
Answer and explanation

Correct answer

A. Verify(mock, times(n)).methodCall()

Why

Mockito's verify function can be used to check that a method on a mock object is called a specific number of times by using the times(n) argument. This helps ensure that the method's interactions meet expected behavior.

Test yourself on Project Structure

A free test with instant, explained results. No account needed.

Start free test
All Project Structure questions →