3 ms·
Test when you lay down abstraction. If you know your expectations about some code, then it's worth testing in proportion to the amount of dependency you have on
by tel 13y ago
Test when you lay down abstraction. If you know your expectations about some code, then it's worth testing in proportion to the amount of dependency you have on those expectations holding.
If you don't yet know the expectations/abstraction you have for some code then you're still deep in the design phase whether or not you like it. Good tests—like good static types or property checks—can be useful to smoke out the properties your abstraction will eventually fulfill. If they slow you down, don't use them.
But once you know your abstraction and start depending on it then please test. Most likely a good test will, right there, show you that you don't actually know your abstraction very well.
- puredanger 13y agoGood advice. Have you tried using contracts (pre/post conditions, assertions, invariant checks) in your code? I find them to be a useful way to encode those expectations in the code before you test.
- tel 13y agoI'm a huge proponent powerful static checking, so I haven't written much code with contracts. My understanding is that they're quite wonderful for dynamic property elaboration, though, so by that fiat I'd say I'm a fan.