3 ms·
Types are wonderful, and a good type system makes so many errors disappear / impossible, that I'd otherwise have to write tests to cover in a dynamic language.
by solraph 3y ago
Types are wonderful, and a good type system makes so many errors disappear / impossible, that I'd otherwise have to write tests to cover in a dynamic language.
Types however, are not a substitute for unit tests. No type system is going to tell me if my income tax calculator covers all the edge cases.
- haspok 3y agoI would argue that your income tax calculator logic should probably not be unit tested, it sounds complicated enough to involve multiple classes / units of code. What you really want to test is business logic, not code logic.
- pasc1878 3y agoSo the unit test is a business case. All tests should be on business logic - code logic might not fit the business case at all and so that should be a fail.
- solraph 3y agoI was using the example of income tax as an entirely theoretical example of where types won't save you in response to the GP. That said, I don't follow what you mean by "to test is business logic, not code logic." To me, that is a distinction without difference. An income tax calculator in a (sane) tax system is essentially a set of pure of functions or classes. This is a perfect place for a unit test. I might have additional unit tests for sub components of the hairy bits, but it's still unit tests all the way.