Skip to content
Sharp

Testing · interview question

When mocking a dependency with Mockito, what method is used to specify the behavior of a method call?

Multiple choiceMediumchapter-10-curatedpremiumtestingcontroller-testing
Choose one answer
Answer and explanation

Correct answer

B. When(...).thenReturn(...)

Why

In Mockito, the when(...).thenReturn(...) syntax is used to define the behavior of a mocked method call, specifying what value should be returned when the method is invoked during the test.

Test yourself on Testing

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

Start free test
All Testing questions →