Many times we thought about that questions, so when should use what
Basic understanding:
When use what:
- Spy: when you want to verify REAL code behavior.
- Stub = Spy + customize behavior of target function by UT code.
- Mock = spy + stub + predefined expectation
OK fine, it is what mentioned document said :)
I just would make something more clear
- Spy and Stub is used only when you have the reference to object which will be faked
- Mock is used for case you do not have the reference to faking object
For example:
- You want to fake behavior of a nested new Object.
- You want to fake behavior of a nested service