I have been programming since the time I was 12. I started writing code to play a text based role playing game called MajorMud. The Mud community called it ‘scripting’ and boy was it controversial, not to mention, a character being played by a script made a very easy target if you were into PVP.

While I spent countless hours making my script smart enough to survive jealous player’s attacks or how to handle an onslaught of zombies I realized that coding would, from here on out be a part of my life.

I got my Computer Science degree and when I joined the corporate world, my company was just getting into Agile development. As part of this we started implementing SCRUM and I was introduced to a new way of coding that changed my life forever. Ok.. well not really, but it did fundamentally change the way I coded software. No longer would I blindly code 100 lines and ‘hope’ I got it right. I faced the cognitive dissonance that the way I learned and was taught in school was the only way.. I saw a better way and have not looked back sense.

Test Driven Development is a fundamental shift in the way you should write code. It is not just for Production code.. no! even when I am writing prototype or just for fun code, a test is the start.

So what is test driven development really you may ask?

A definition that I prefer is:

    TDD = Test First Development +  Refactoring

The scope of TDD that I am talking about in this blog is really around unit tests. To do this, you need to have some kind of automated unit testing framework. The most famous are JUnit, NUnit and CppUnit depending on your coding language.

How do you do it? It is simple:

  •     Write the test, run the test (it should fail)
  •     Write the code to make the test pass
  •     Move on to the next test
  •     Refactor & Repeat


Some additional rules I like to follow:

  •     No Non-Test code is written unless a test is failing.
  •     Do the simplest thing you can think of to make the test pass then move on!


For a real time example, check out this video I made:
http://www.youtube.com/watch?v=LsPIjyFpSKk

I go through an exercise where I create a Palindrome checker! A very simple example but it gives you a crash course on how TDD works.

TDD is much easier when you are starting on a fresh project. It can be a challenge if you are dealing with a legacy code base but it can be done (Yes I have done it!).

I have also personally seen how test driven development has increased quality in my own coding and in the various teams I have been involved with.

TDD all the WAY!

Posted By Brian Lawrence.