Speaker
Edwin Jung
Material
Note
Mock hell
- complex patch targets
- numerous mocks or patches
- mocks with brittle assertions
- mocks with complex setup
- deep mocks/recursive mocks/mocks returning mocks
- tests that test nothing
- using the debugger to reverse-engineer mocks
- mocks that prevent refactoring
How to test without mock
-
mocks aren't stubs
-
test doubles
name | behavior |
---|---|
mock | records calls to the object |
stub | returns canned data, no logic |
fake | implements fake version of production logic |
dummy | does nothing |
spy | records and delegates to the real thing |
- alternatives
- fake patch
- fake injection
-
tactical questions
- Which test doubles (mock or other)?
- Mockist or classical?
- Patch or inject?
-
tactics
- Find a Seam, Patch a Fake
- mock roles not objects
- Dependency Injection
- Inject the Collaborator
- Go Functional
Conclusion
- always be refactoring
- consider other test doubles
- patching should be rare, and the last tool you use
- mocks (if you use them)
- should target roles and not objects
- are not just for test isolation