Skip to content
Sharp

Testing · interview question

In a test using Mockito, how do you specify the behavior of a mock object when a specific method is called?

Multiple choiceMediumchapter-10-curatedpremiumtestingmocking-with-mockito
Choose one answer
Answer and explanation

Correct answer

D. Using 'when().thenReturn()'

Why

The 'when().thenReturn()' pattern in Mockito is used to define the behavior of a mock object when a specific method is called. This allows you to specify what the mock should return or do when the method is invoked, without calling the actual method.

Test yourself on Testing

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

Start free test
All Testing questions →