4 ms·
This is usually called the classical vs. mockist, or test interactions vs. test final state debate. Instead of mocks, some people prefer to build fakes / stubs
by danidiaz 8y ago
This is usually called the classical vs. mockist, or test interactions vs. test final state debate.
Instead of mocks, some people prefer to build fakes / stubs which are versions of a dependency which are "fully operative" in a sense but with a simplified internal implementation. For example a repository that keeps entities in memory. (Not the same as an in-memory database! The fake repository wouldn't use SQL at all.)
Tests would check the final state of the fakes after the interactions, or simply verify that the values returned by the tested component are correct.
The hope is that fakes, while possibly more laborious to set up, allow an style of testing that focuses less on the exact interactions between components, and therefore is less brittle.
Some links:
- Mocks aren't stubs https://martinfowler.com/articles/mocksArentStubs.html#ClassicalAndMockistTesting https://martinfowler.com/articles/mocksArentStubs.html#Class...
- From interaction-based to state-based testing http://blog.ploeh.dk/2019/02/18/from-interaction-based-to-state-based-testing/ http://blog.ploeh.dk/2019/02/18/from-interaction-based-to-st...