Why You Don't Get Mock Objects
summary
Mocks assert messages between objects not internal state, so use them in object‑oriented, tell‑don’t‑ask designs rather than procedural code. Example: replace a real ticket reserve system with a mock request handler and assert it should receive reserve with 55 when submit is pressed. Follow concrete rules: mock roles not objects, only mock types you own — don’t mock external APIs or internals; test boundaries with integration or acceptance tests. Read Growing Object‑Oriented Software Guided by Tests for the patterns.
AI-written summary · about
chapters (27)
- 0:00Introduction
- 1:13I Am A Secondary
- 3:07Mock Objects Have Been Called
- 5:51The Tests Fail
- 7:28Procedural Programming
- 7:52Mocks Assert On Messages
- 9:01Key Idea In OOP
- 9:26The big idea is "messaging" -- that is what the kernal of Smalltalk/Squeak is all about... The key in making great and growable systems is much more to design how its modules communicate rather than what their internal behaviors should be.
- 10:53(Contrived) Example
- 12:34What Would The Code For The Interface Look Like?
- 13:14Notice Two Things
- 19:10Key Mocking Rules
- 19:28Mock Roles, Not Objects
- 19:44Wanting To Mock Concrete Objects Is A Design Smell
- 21:27When Mocking Roles, TDD Becomes A Design Process
- 25:56Instead Of Mocking A Role, Your Mocking An Implementation
- 26:08Duplicating Your Production Code In Your Test Is A Test Smell
- 27:29What Should We Do?
- 27:55Implement The Display Object Using Puts
- 28:54What About Testing The Display Object?
- 29:40Integration Tests / Acceptance Tests
- 30:26Only Mock Peers, Not Internals
- 31:33Key Question
- 32:47Different Types Of Messages Come In
- 35:23Internal Object
- 35:40It's An Implementation Detail
- 36:12Further Resources
related talks
36mTo Mock or Not to Mock
28mTo mock, or not to mock?
39mIntro to Mocking: Why Unit Testing Doesn't Have To Be So Hard
27mReal World Mocking in Swift
43mTest Driven Design - Coupling Loosely
31mBeyond the Mockery- Why We Should Embrace Testing Without Mocking Frameworks
24mMaking Mock Objects More Useful
59mYour tests are mocking you
