- 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:
- I feel I’m a much better developer when I write code with tests.
- I’ve incorporated testing into my coding work flow so it feels natural to me to write tests with code.
- 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.
- Tests make refactoring so easy to get into, and refactoring makes ugly code so much easier to work with. I love refactoring ugly code.
- Not having tests with my code makes me feel nervous and dirty
- Seeing tests in other people’s code(gems, plugins) makes me feel more confident about using their code in my own applications.
- 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:
- It’s not a guarantee of bug free code.
- It sometimes takes much more time to write the tests than it does the code.
- It’s impossible to mandate others to use TDD or unit test.
- It takes a lot of discipline and ability to not lose your cool when time is short and tests are hard.
- I’m not perfect sometimes I just skip the tests because I’m tired that day.