Mocks, Stubs, and Spies, Oh My
summary
Defines five test doubles with concrete rules: use mocks to record calls and verify indirect outputs, prefer lenient over strict mocks to avoid brittle order checks; use stubs to supply indirect inputs including responder and sabotuer behaviors; use spies to wrap real implementations and inspect internal state; use fakes as in-memory replacements (fast DB substitute) for integration tests. Calls out Mockito as the mocking tool that blurs terms and warns that overusing doubles makes tests overspecified and fragile.
AI-written summary · about
chapters (15)
- 0:00Introduction to test doubles
- 1:08Test pyramid overview
- 3:35When to use test doubles
- 4:59Mocks explained
- 7:26Mocks in unit tests
- 9:09Stubs and their role
- 11:56Stubs in testing
- 13:01Spies as test doubles
- 15:29Dummies in testing
- 16:55Fakes for performance
- 20:08Terminology confusion
- 23:17Mockito’s test doubles
- 25:50Best practices for test doubles
- 27:36Overusing test doubles
- 28:39About the speaker
related talks
36mMocks, Stubs, and Spies, Oh My!
42mMocks, Fakes, Stubs – Is There a Difference? Do You Still Need Them?
41mMocks vs Fakes vs Stubs
40mTest Doubles are Not To Be Mocked
47m"Testing with Doubles: Why, When, and How?"
59mJava Testing Part 2: Mocks, Stubs, and Spies with Mockito 4
38mDoublers in Tests. Wiremock vs Mockito
31mBeyond the Mockery- Why We Should Embrace Testing Without Mocking Frameworks
