Wednesday, May 18, 2011

Test-Driven Development - Are you doing it right?

Recently I have been doing test-driven development (TDD) exclusively in both Java and C#, and I have made great progress in doing it the right way. I was fortunate to learn the right way from Uncle Bob who my employer invited for a TDD in-house training course for our engineering team.

So how do you know that you are doing it right?

Here are the signs that you are on the right path:
  • You are writing more tests than ever before 
  • Your test coverage is creeping up to > 90%
  • You create a test class before creating the class under test
  • You write a failing unit test before making any code changes
  • Your test classes are longer (more lines) than the class under test
  • You start to feel itchy when you write a line of code that is not making a test pass
  • You are more confident in the code you are writing
  • You are refactoring your tests
  • You are not deploying and debugging every time you change the code
  • You are debugging tests rather than production code
Doing TTD is not easy and requires that you stop following old habits and force yourself to do it properly for a few weeks. For me it was a slow off-and-on process, but as I do more and more of it, I find that I am getting my development speed back, with an added boost of confidence provided by over 90% code coverage. Yes, I have tests to prove it!

No comments:

Post a Comment