In this article, author is explaining the importance of TDD in age of Agile.
In age of Agile framework TDD is a very important aspect of Application development because what we are going to implement is more valuable than how we are going to implement. It doesn’t mean that I am advocating of missing the how, it is really important but when we start to work on any feature/product we must know In and Out of that, and to ensure that I advise to go with TDD.
TDD is a grouping of TFD (Test First development) and Re-factoring.
Code First OR Test First ?
Now it’s easy to understand that in agile framework development team (in agile known as feature team) job is to first write the tests before writing the code. So before implementation all tests should fail and after implementation tests should pass, and even if tests fails, code should be re-factored to ensure it passes. They should add more tests after re-factoring to make sure that it won’t miss any functional testing.
To go with TDD, feature team and any management involved should have the mindset accordingly as quality of development is the key agenda of this philosophy and need a focused team who should understand well the requirements.
Writing Tests before code modules exists
Let me elaborate that how to approach of writing tests before code modules exists.
In agile framework, feature team members chooses the feature to implement and feature team is getting involved to understand the requirement as well, so they know that what feature they are going to implement. They should start writing Unit tests considering that what input would be for your feature and what output feature will produce. You can write all the possible tests considering the feature module as a black-box (abstract). Since module is not implemented all tests should fail, and now start writing the feature implementation code, and again run all the tests and all should pass, re-factor the code if required and again test and so on.
JUnit can be used for Java based development, Selenium can be used for java based web development, DBUnit can be used for DB development, Fitnesse can be use for User acceptance testing etc. You can use mocking for unit testing as per your requirement.
The aim behind TDD is to motivate feature team (development team) to understand the requirement well before writing any code which ensures fast development and minimal bug. Another aim is that it is always easy to trace any error or bug in initial stage as number of lines of code is less and can be re-factored that time itself.
So start using the Test Driven Development to create a high quality application.