Hacker News new | ask | show | jobs
by nakajima 6518 days ago
The advantages described by the author here are the same ones you always hear in discussions about the benefits of unit testing (bugs are caught sooner, you feel better about your code, etc.)

The real benefit to unit testing (at least from my experience) is that it encourages you to write better code up front. By thinking in terms of the smallest possible units, you don't bite off more than you can chew. As a results, your code tends to be more decoupled, more modular, and more logical (unit testing helps you organize responsibilities in your code).

For this reason, even if I had to delete every test I wrote after I made it pass, I'd still write a failing test before writing any implementation code. Of course I'd much rather prefer to keep my test suite, since it does provide the benefits discussed by the author. While no amount of unit tests will reveal every bug in your code, the quality of code I've written after writing a failing test first is vastly superior to code I've written sans-test.

Your mileage may vary, but if you haven't tried it yet, I suggest you give it a whirl.