Difference between Stub object and Mock object in Unit Test

Anil Sutariya
Jul 29, 2017 · 1 min read

Stub object. A stub object (also known as a stub), is a fake
object that can be used in place of a real dependency, is significantly easier to instantiate, and provides harmless method implementations of the object it is trying to emulate.

Mock object. A mock object (also known as a mock), is similar to a stub. However, the key difference is that a mock is used in a test assertion, or asserted against.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade