Definition:
A technique commonly used in automated unit test for dummy implementation of a software component. The mock objects are simulated to behave like a real object in a controlled manner as part of the testing initiative.
Benefits:
It is very useful when the real object is difficult to incorporate into a unit test such as;
- The complex real objects supply non-deterministic results
- It is in a state difficult to reproduce
- It is slow and may change behaviour
Mock objects can do decoupling of software components for testing purposes.
Origin:
- Freeman, Mckinnon and Craig described it as a testing technique in their article ‘Endo-Testing: Unit Testing with Mock Objects’ in 2000
- Freeman and Pryce’s provided comprehensive description of mock objects integration to TDD and OO design in ‘Growing Object-Oriented Software Guided by Tests’ in 2010
Further Reading:
- ‘A brief History of Mock Objects’ by Tim Mackinnon
- ‘Using Mock Objects for Complex Unit Tests’ by IBM DeveloperWorks