Mockito – @Spy vs @Mock

Technically speaking both “mocks” and “spies” are a special kind of “test doubles”.

Mockito is unfortunately making the distinction weird.

A mock in mockito is a normal mock in other mocking frameworks (allows you to stub invocations; that is, return specific values out of method calls).

A spy in mockito is a partial mock in other mocking frameworks (part of the object will be mocked and part will use real method invocations).

Leave a Comment