Mocks, dummies, spies, fakes - testing your code
Testing code has different definitions and sometimes can mean different things for different people. this post is a collection for easy to come back definitions on mocks, dummies. stubs, spies and fakes.
Table of contents
Mock is frequent used interchanbealy with the term test double, mock is often used for people that didn’t read the paper definition of mock. Then, developers got used to the term mock instead of test double. Mocks, refers to the whole family of objects that are used in tests . On the other hand,  defines this technique as substitutes or mocks objects.
Despite of the family of mocks and its definition, the goal using this technique is to test a unit of code in isolation, without touching its dependencies.
You pass in something, and you don’t care who it is used, often the object is not used at all.
Opposed to dummies, stubs are objects created in a way that you do care how they are used. For example, to tricky an authorization to test if the user ca/can’t do certain actions in the system.
To assert that a method was called by the system under test, as the post by : “You can use Spies to see inside the workings of the algorithms you are testing”.
Is interested in the behavior, instead of return of functions. It cares about which functions were invoked, with what arguments and how often.
Fakes have business logic, so it can drive the system under test with different sets of data.
- R. C. Martin, “The Little Mocker,” 2014 [Online]. Available at: https://blog.cleancoder.com/uncle-bob/2014/05/14/TheLittleMocker.html. [Accessed: 29-Nov-2020]
- S. Freeman, “Growing Object-Oriented Software, Guided by Tests,” 2009 [Online]. Available at: https://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627. [Accessed: 08-May-2021]