| 1 | # Interface Design for Testability |
| 2 | |
| 3 | Good interfaces make testing natural: |
| 4 | |
| 5 | 1. **Accept dependencies, don't create them** |
| 6 | |
| 7 | ```typescript |
| 8 | // Testable |
| 9 | function processOrder(order |
| 10 | |
| 11 | // Hard to test |
| 12 | function processOrder(order |
| 13 | const gateway = |
| 14 | } |
| 15 | ``` |
| 16 | |
| 17 | 2. **Return results, don't produce side effects** |
| 18 | |
| 19 | ```typescript |
| 20 | // Testable |
| 21 | function calculateDiscount(cart |
| 22 | |
| 23 | // Hard to test |
| 24 | function applyDiscount(cart |
| 25 | cart.total -= |
| 26 | } |
| 27 | ``` |
| 28 | |
| 29 | 3. **Small surface area** |
| 30 | - Fewer methods = fewer tests needed |
| 31 | - Fewer params = simpler test setup |