Stubbing and Mocking
Description
Stubs and mocks allow programmers to simplify tests by reducing dependencies and setup. This sounds great, but in practice it can become frustrating to work with.
Pros:
- Reduce test setup
- Faster tests
Cons:
- Refactoring requires going through every stub/mock and updating them
- Possibility for bugs if a stub/mock isn’t updated when the real code is
- Can end up causing long/complicated chains of stubs/doubles to simulate real modeling
Technology Status at Wunder
Discouraged.
There are situations where we still use (and will continue to use) stubs and mocks, but in most cases we would like to avoid them in the future. The primary case where they are useful is for service boundaries. Stubbing service boundaries allows to better isolate our service level tests and avoid long/complicated test setup. Outside of that use case, we prefer to avoid mocks/stubs anywhere else in the code due to the problems outlines above.