3 ms·
1. Define your APIs in terms of "what" it should do, not "how" (which is for the implementation). 2. Use protocols/interfaces in Swift/Java to define APIs. 3.
by tsycho 3y ago
1. Define your APIs in terms of "what" it should do, not "how" (which is for the implementation).
2. Use protocols/interfaces in Swift/Java to define APIs.
3. Then write tests to the API's public contract, without using internal implementation details.
Tests written in the above way will actually detect bugs, and stay stable to internal implementation changes that don't affect the external behavior.
- tvaughan 3y agoPoint 3 is the key. Code coverage should only be measured by tests that only use the “external API.”
- sixstringtheory 3y agoBrilliant distillation of this insight, I've never heard it put in those words before but it's perfect. It cuts both ways too, if you have lots of tests but most of them aren't really exercising the external API, then you're worse off.