WWDC 2017
- Engineering for Testability - Friday
- Testable App Code
- Scalable Test Code
- Treat your test code with the same amount of care as your app code
Session video and resources: https://developer.apple.com/videos/play/wwdc2017/414/ This is the best session !
- Prepare input
- Run the code being tested
- Verify output
- Control over inputs
- Visibility into outputs
- Reduce references to shared instances
- Accept parameterized input
- Introduce a protocol
- Create a testing implementation (mocks)
- Extract algorithms into separate types, away from the code using side effects
- Functional style with value types. Input -> Outputs
- Thin layer on top to execute effects
- Testing pyramid -> UI, Integration Tests, Unit Tests
- Store part of queries in a variable
- Wrap complex queries in utility methods
- Reduces noise and clutter in UI tests
- Encapsulate common testing workflows
- Cross-platform code sharing
- Improves maintainability
- Avoid working through menu bar for macOS
- Make code more compact
- Important to consider even though it isn't shipping
- Test code should support the evolution of your app
- Coding principles should apply to tests as well
- Code reviews for test code, not code reviews with test code