4 ms·
There are a couple of reasons why you should/ could write tests: - for catching regressions in the future - to verify that your code works. How else would you
by misja111 10y ago
There are a couple of reasons why you should/ could write tests:
- for catching regressions in the future
- to verify that your code works. How else would you know that your backend service reacts properly on some edge condition
- as documentation
- as a kind of quality mark, for instance to be able to pass a code review or when writing code for an external party
Unfortunately the last reason is also the most useless and still it is the one that seems to be the main motivation for many big enterprise developers.
- TallGuyShort 10y ago>> - as documentation Thank you for including this - it's underappreciated. So many times recently I've needed to write code against some poorly documented API (not always due to lack of effort, some things are hard to document well in prose / JavaDocs, or just due to constant change), but I took one look at the unit tests and it all made sense - and I knew it was up to date for the latest work.
- Freak_NL 10y agoTests are great for dyslexic colleagues as well. A good clear concise unit test is often easier to grasp than the best of API documentation (e.g., JavaDoc in Java).
- TallGuyShort 10y agoGood point - I'd bet it applies to autism and such too.
- euyyn 10y agoI think it applies to everybody. I think it was Terence Tao who had a blog post claiming (and showing) that teaching by example first is the most effective.
- mannykannot 10y agoI know this is not formally an ordered list, but it looks cart-before-the-horse-ish to have catching future regressions before verifying that it works in the first place. (This comment is effectively a reply to the OC's claim that we don't test to verify.)