I was going through an online course on test driven development and came across the concept of test doubles. As per the definition of test double in the course :
Test Doubles : Test doubles are objects that are used in unit tests as replacement to the real production system collaborators.
I got an idea what test doubles mean. But then it was mentioned there are various types of test doubles. The ones mentioned in the course were :
Dummy : Objects that can be passed around as necessary but do not have any type of test implementation and should never be used.
Fake : These objects generally have a simplified functional implementation of a particular interface that is adequate for testing but not for production.
Stub : These objects provide implementation with canned answers that are suitable for the tests.
Spies : These objects provide implementation that record the values that were passed in so they can be used by the tests.
Mocks : These objects are pre-programmed to expect specific calls and parameters and can throw exceptions when necessary.
I have worked with mocks before and do have a brief idea of what they are and how to use them. Though I was confused regarding the other mentioned types of test doubles.
Can someone help me with difference between these types of test doubles and when to use one ?