There is a point to this story, but it has temporarily escaped my mind...
Contact Me MyFaceBook MyLinkedIn MyGitHub MyTwitter

Mocks vs. Stubs

Mocks and Stubs are used in a similar fashion up to a certain point. They are used when creating the real object would be “expensive” and may not be repeatable. They also allow you to isolate the code under test. They simulate the object under test.

Mocks

A mock is used to test behavior. A mock validates that all expectations were met. You are worry that the right calls were made. Were the calls made in the correct order? Were correct number of calls made? Did your code interact with the resource correctly?

Stubs

A stub is used to test state. With Stubs, you are passing data in, getting data out, calculations, evaluating, doing assertions. If you were to comment out a call in a test with a stub, that test would still pass.

Copyright © 2015 by Julian Easterling. SOME RIGHTS RESERVED.

Creative Commons License
Except where otherwise noted, content on this site is
licensed under a Creative Common Attribution-Share Alike 4.0 International License.


All of the opinions expressed on this website are those of Julian Easterling and
do not represent the views of any of my current and previous clients or employers in any way.

If you notice an error on the site or content that has not been properly attributed, bring
it to my attention using the contact page and I will endeavor to fix it as soon as I can.

I accept no responsibility or liability for any damages incurred by following any of
my advice or by using any of the information on my site or of those sites that I link to.