Testing Mock vs Stub

Andre Pratama
MeetU Engineering
Published in
1 min readMay 15, 2018

What’s the difference beetween mock and stub?

Stub is an object that holds predefined data and uses it to answer calls during tests. It is used when we cannot or don’t want to involve objects that would answer with real data or have undesirable side effects.

for example :

in the code above we do stubbing to dataMock.

then, Mock is “ objects that register calls they receive.
In test assertion we can verify on Mocks that all expected actions were performed.

For Example:

In the code above we verify viewMock, in Mock we usually make some expectation.

That’s it, thank you.

Source:

--

--