Writing a truly testable code
summary
Argues that testability requires removing implicit inputs and outputs and passing everything through explicit APIs and DI, using Android, MVP, Kotlin, Rx and Dagger 2 as concrete examples. Shows failures: flaky Rx tests that fail on fast machines because schedulers are implicit and locale/time formatting tests that break across timezones. Describes the fix of injecting schedulers and time providers, using header interfaces and mocks, and a short-lived hack that forced tests onto a slow CI before the real make time an injected dependency fix. Also proposes wrap platform APIs and build up the dependency graph from leaf modules.
AI-written summary · about
chapters (11)
- 0:00Introduction and thanks
- 3:16Why write tests
- 6:07Truly testable code definition
- 13:08Explicit inputs and outputs
- 16:54Time as a dependency
- 18:21Schedulers in testing
- 22:12Locale and formatting issues
- 24:43Abstracting platform dependencies
- 29:28Mocking dependencies
- 31:36Refactoring for testability
- 35:17Summary and closing
