4 ms·
A while back I described the benefits I think unit tests give you: 1. Well-tested parts 2. Decoupled design 3. Rapid feedback 4. Local context to test in.
by henrik_w 11y ago
A while back I described the benefits I think unit tests give you:
1. Well-tested parts
2. Decoupled design
3. Rapid feedback
4. Local context to test in.
At the same time, there are many cases where they don't help much. More here: http://henrikwarne.com/2014/09/04/a-response-to-why-most-unit-testing-is-waste/ http://henrikwarne.com/2014/09/04/a-response-to-why-most-uni...
- Scarblac 11y agoThey are also a word of encouragement to whoever sees your code for the first time because he needs to make a change in it, five years from now. "Look, this code looks strange to you, you would have done it differently, and you are afraid you might break things you don't even know exist. But fear not, there are tests, they run, and they will guide you." It's always relieve to find that some random old crap is actually well tested.
- Freak_NL 11y agoNot just to someone else. Nothing is more pleasant than going in to refactor code you wrote years ago, and find that you wrote comprehensive unit tests. Thank you past-me!
- tomp 11y agoI think you're missing the most important one: ensuring you don't unexpectedly break your own code in the future (when you come back in 6 months and forget why exactly it's arr[1:n-1] not arr[0:n-1] or arr[1:n]).
- falcolas 11y agoSounds like a well placed comment would be of more value than a test there.
- deleted 11y ago[deleted]
- CamatHN 11y agoComments are easy to miss though. We arnt perfect about going through our code and testing gives us objective measures.
- falcolas 11y agoA test won't say why code is the way it is; it will simply provide some sample input and expected output to that code. This may be enough, but not always.