sharp bites

standing on the shoulders of giants

Write your test first... because adding them later sucks

So true. As jason points out:
  • It’s boring. Write the obvious tests. Check code coverage - what did I miss? Write more tests capturing more edge cases. Wash, rinse, repeat. Ugh.
  • It’s not trivial. I’m trying to put tests around code that was created months ago, and trying to capture the mental state of the coder and what he was doing is damn near impossible.
If you write the test first, you get all the benefits of TDD.
  • You don’t get just unit testing, but instead you let your design lead your development.
  • As you are writing the minimum code necessary to achieve the behaviour your test is checking, you end up with full code coverage.
  • You can refactor as you test-and-code (and test, and code,…), and you have your tests to cover your ass as you go. If you need to refactor when it’s all finished, poor you. You are just left out in the wild.

Comments