(Via haacked.com/ .)
I mildly disagree with Sam and Phil.
“But as Sam points out, what use is better code if it does the wrong thing?”
Yes, but what happens to your unit tests when you refactor your code to meet the new requirements? Now, you not only have to refactor your code, but you also have to refactor your unit tests. Also, writing unit tests, first, last, or during, doesn’t guarentee that your code will meet the requirements after the first, second, or N refactor.
My feeling is that unit tests are the new “documentation”. Unless you spend as much time babysitting your unit tests as you do your code, they become hopelessly outdated and are instead written after the fact. Which really just means you’ve increased the amount of code you have to write by two-fold. That doesn’t include all the build scripts, and setup of the automated testing software.
Plus, I’ve always wondered, what unit tests the unit tests? How can you ensure that your unit test is testing your code correctly? π