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.