Writing Testable Code
summary
Claims that rebuilding 180,000 lines with 3,000 unit tests produces only three production bugs over two years and ties testability to low maintenance effort. Shows concrete refactors: breaking large promise spaghetti into smaller functions then converting promises to async/await for fewer paths to test. Demonstrates constructor injection and mocking by passing collaborators into constructors to replace globals and singletons, and reports that these changes make unit and integration tests straightforward and reliable.
AI-written summary Β· about
chapters (19)
- 0:00Writing testable code
- 1:24First job's testing lessons
- 3:32Testable code traits
- 5:37Refactoring promise-based code
- 7:45Breaking promise chains
- 9:06Async/await simplification
- 10:14Avoiding heavy constructors
- 12:02Why constructors fail tests
- 13:48Passing dependencies
- 14:08Managing collaborators
- 15:12Reducing dependencies
- 16:35Brittle state and singletons
- 17:58Spooky action in tests
- 19:22Wrapping global state
- 20:45Mocking global dependencies
- 21:49When global state is okay
- 22:11Classes doing too much and how to fix
- 22:55Breaking down classes
- 23:36Code for others to test
related talks
43mUnselfish Testing
56mIf You Won't Test Your Code, Who Will?
45mTesting Legacy Code - What To Do When It Seems Untestable
44mTesting the untestable - patterns and use cases analysis
37mClean Test Code
26mTesting the Tricky Stuff
34mBetter Code Through Boring(er) Tests
31mSustainable way of testing your code
