Mock object |
In object-oriented programming, mock objects are used for test-driven development. In tests, a mock Object (computer science) behaves exactly like a real object with one crucial difference: the programmer will hard-code return values for its methods and define expectations for the number of times each method will be called. The arguments passed to the mock object methods at each function call can also be defined.
Mock objects could be thought of as sketches. They re highly detailed in terms of specifying the interface and behaviour expected by the primary object but go no further than that - all that is required in order to create the primary object and its unit test.
Once the primary object and its test are complete, the programmer moves on to write implementations for any mock objects discovered in the test. The new classes must provide the behaviour specified by the mocks.
Mock objects and test-driven development are top-down design tools that allow the programmer to start by writing one class, and then watch the design ripple out from there.|
|