I like unit testing a lot. I’ve recently been thinking about whether it really is everything that advocates like myself make it out to be. I’m still thinking, but I reckon that language has something to do with it, and that I wouldn’t like TDD so much if I were writing in Haskell. Maybe.
Anyway, here are the benefits of unit testing, without justification or explanation:
- Easier to maintain code - Avoiding regressions - Make API clearer, both by describing it and by encouraging contracts. - Confidence in changes to code
For new contributors, there are other benefits:
- Confidence in changes to code - Confidence in the validity of your own patch - Mechanism for exploring internal system behaviour
Some of the costs are:
- Maintaining tests - Caring about the performance of tests - Running the tests - Debugging tests
For new contributors, there are other costs:
- Finding tests - Figuring out how to run tests - Figuring out how to write tests - Learn unit testing
Is this fair? Is this clear? And exactly where was that post by that guy about unit testing being overrated?
On a half-related and slightly exasperated note, many of the conversations I’ve been having recently have been about costs and benefits. What happened to doing something because it was the right thing?