Testing Randomness
summary
A simple two-player dice game is implemented, then shown failing silently: tests that mirror code logic stay green but miss cases. The team builds a Dice abstraction, injects a fake dice into tests, and adds dependency injection so changing the real die (from 1–6 to 1,1,3,4,5,6) no longer breaks behavior tests. Tests become deterministic; adding event logs records each roll and the reason for the winner so bugs are reproducible. Time travel or injected current time is recommended for clock-driven code.
AI-written summary · about
chapters (27)
- 0:00Introduction and story setup
- 1:56Starting the game implementation
- 3:01Writing initial tests and code
- 5:13Adding draw condition to the game
- 8:07Fixing flawed test logic
- 9:17Using stubs for deterministic tests
- 11:48Introducing the better dice
- 12:54Refactoring with dependency injection
- 16:37Creating a fake dice for testing
- 19:50Dependency injection in practice
- 21:15Customer complaint reveals flaw
- 22:18Adding game event logging
- 24:51Analyzing test flaws and fixes
- 25:13Problems with logic in tests
- 27:23Stubs and mocks pros and cons
- 30:17When to use mocks and stubs
- 30:39Dependency injection in tests
- 31:41Instance doubles and team acceptance
- 32:45Challenges with fake implementations
- 33:47Logging and auditing in tests
- 35:54Testing randomness without testing randomness
- 37:22Time travel for testing time-dependent code
- 38:09Q&A on testing time and randomness
- 39:15Keeping test doubles in production code
- 40:41Ensuring fake and real implementations align
- 42:08Team ownership of test doubles
- 43:31Final Q&A and closing remarks
