Create Mock Object
When unit testing, you are often interested in testing a portion of a complete system,
isolated from the components it depends on. To test a portion of the system, we can
substitute mock objects to replace the depended-on components. A mock object
implements at least part of the same interface as the production object, but often in a
manner that is simple, efficient, predictable, and controllable. When you use the mocking
framework, the component under test is unaware of whether its collaborator is a "real"
object or a mock object.
For example, suppose you want to test an algorithm for buying stock, but you do not want
to test the entire system. You could use a mock object to replace the functionality of
looking up the stock price, and another mock object to verify that the trader purchased
the stock. The algorithm you are testing does not know that it is operating on mock
objects, and you can test the algorithm isolated from the rest of the system.
33 Unit Testing