Tuesday, 24 May 2011

The Three Laws of Test Driven Development

I’ve mentioned Test Driven Development several times in this blog, but haven’t yet got around to defining its three principle rules. These were, I think, first documented by Bob Martin in IEEE Computer Society Journal of May/June 2007. To summarise, the three rules are:
  1. First Law: You may not write production code until you have written a failing unit test.
  2. Second Law: You may not write more of a unit test than is sufficient to fail and not compiling is failing.
  3. Third Law: You may not write more production code than is sufficient to pass the currently failing unit test.

These laws are good because they force you to get each piece of code working (i.e. passing a test) before you can write the next piece of code.

For more information on TDD take a look at wikipedia.

No comments: