This gist aims to explain the difference between stubs and mocks and when each should be used. For an introduction to stubs and mocks, start somewhere else, like here.
-
Stub: used to isolate the object under test from its dependencies, preventing the test from being influenced by code outside the object. This way the test can't be made to fail or be broken by code which is not part of the specific functionality being tested. Stubs also lead to less code being run, which helps keep tests fast. A stub has no expectations. It doesn't care if it is called or how many times.
For example, you might stub out a message sent to a database connection if all you are trying to test is the type of the method's return value.