Karmacrash

Tim Case serves ruby with oxtail marmalade

Why Unit Testing And TDD Is For Me

- April 30th, 2008 02:32

I adopted ruby as my preferred programming language a couple of years ago and one of the things I did during the switch (from .NET) was to become a TDD developer. I started writing tests from the very first moments when I adopted the language. Part of the motivation to learn Rails came after I saw how easy it was to unit test with the baked in support that Rails provides. After years of writing tests I can confidently state the following:

Why I love code with tests:

  1. I feel I’m a much better developer when I write code with tests.
  2. I’ve incorporated testing into my coding work flow so it feels natural to me to write tests with code.
  3. Small, discrete tests allow me to concentrate deeply on a small piece of an application and then when I feel I’ve tested and constructed a small piece of code, I have comfort that I can forget about it and move on to other things. It frees up my mind.
  4. Tests make refactoring so easy to get into, and refactoring makes ugly code so much easier to work with. I love refactoring ugly code.
  5. Not having tests with my code makes me feel nervous and dirty
  6. Seeing tests in other people’s code(gems, plugins) makes me feel more confident about using their code in my own applications.
  7. As documentation, I prefer tests to comments. I’ve successfully used tests to understand how other people’s code was intended to be used.

What I recognize about Unit Testing:

  1. It’s not a guarantee of bug free code.
  2. It sometimes takes much more time to write the tests than it does the code.
  3. It’s impossible to mandate others to use TDD or unit test.
  4. It takes a lot of discipline and ability to not lose your cool when time is short and tests are hard.
  5. I’m not perfect sometimes I just skip the tests because I’m tired that day.