To TDD or not to TDD – Yet another chicken-egg situation ?

By jpnair

Before trying to answer the above question, let us quickly touch base on what is the difference between the terms ‘Unit Testing’ and ‘Test Driven Development (TDD)’, or is there a difference at all?

 Here’s what. Unit Testing simply means that you write unit test cases to exercise minute parts of the codebase. The term ‘Unit Testing’ by itself doesnot state the chronological order, ie whether the code comes first and then the unit test case is written, or was it the other way round, ie whether the test case is written first. The latter is actually a simplistic definition for TDD. That is, write unit test cases first and then write code to satisfy those test cases.

 So TDD is actually the next step in the evolution of Unit Testing, in that the test cases are written upfront, before the code is written, thus providing various advantages. The code that comes out of TDD is rock solid, high quality, better designed, easily testable (especially regression testing), and easily maintainable (one of the reasons being that the test cases act as documentation). So from that perspective, the question whether TDD makes sense or not, ie whether the code should be written first and then the test case or should it be vice-versa, is a no-brainer (IMHO). TDD has come way beyond the hype stage, and writing test cases first definitely makes proven sense, but whether it will be successful or not, depends wholly on the way it is implemented, the acceptance of this within the team, and the management support to make it work. That’s asking for too much, eh? There are several pitfalls that you need to watch out for, in your journey towards TDD. We’ll examine these in a separate post.

Anyway, TDD is not the be-all-end-all of Agile. If you’re able to make it work, great, you’ll see the benefits. But if you’re not, don’t fret, there are other tenets in Agile which can be implemented easily and fetches good results. We’ll examine some of them in the forthcoming posts.
Ciao 

 

 
 
 

 

 

 
 
 
 

 

 

 

 

 

Tags: , , , , , , , ,

Leave a Reply