Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created October 24, 2019 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/88d9a8ba3f33ce801ead28f04bbb65d3 to your computer and use it in GitHub Desktop.
Save Integralist/88d9a8ba3f33ce801ead28f04bbb65d3 to your computer and use it in GitHub Desktop.
[Fakes vs Stubs vs Mocks] #fakes #stubs #mocks #testing

Fakes

Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (e.g. a working version of a datastore that has a get and set method but writes to local disk rather than actually writing to a database).

Stubs

Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'.

Mocks

Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

Additionally, mocks are seen as a thing that we will assert validations against. They have the responsiblity of recording how it was, or wasn't, used (e.g. "assert that an API were called with xyz values", "assert that an endpoint was not called", etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment