Terminology Disclaimer

These terms are loosely defined and used interchangeably.

Most of the time, mock is common for all types.

Image Credit: Pragmatists Blog

Stub

  • method stub
  • Shortcut implementation of a method
  • Typically returns hard-coded data
  • Mimic external function calls and possible results
  • Test error states as well as expected states

Image Credit: Pragmatists Blog

Fake

  • fake object
  • Mimic a real object
  • Satisfy type checker
  • Contain/Return default data
  • Simple implementations

Image Credit: Pragmatists Blog

Mock

  • test spy
  • Mimic a real object
  • Track all operations
  • Verify that our code calls other code
  • See side effects of our code beyond return values