TDD is one of the core methodologies of “Extreme Programming”. Kent Beck is founder of Extreme Programming. Extreme Programming (aka XP) has been successful as it emphasis more on Customer Satisfaction. XP encourages to keep the design very simple and straight forward. XP significantly changes the way we code, it drifts from the traditional style of coding. XP is best suited when the requirements change dynamically. We might have a system whos functionality changes every few months. Some times requirements change when the customer is not very clear about what he wants. Lastly the developer’s productivity increases using XP.
Test Driven Development is known as “Test First”. TDD lays more stress on through unit testing. It’s a usual practice to write and execute test cases after the coding is complete. Goal of TDD is to write a clean code. But in TDD, first we write test cases, write the code and execute test cases. So that’s the reason it’s called “Test First”. It requires a different mind set from developers.
In tradition software practice we follow the below steps.
Create the Technical Design Document.
Write the Code.
Create Unit Test Cases.
Test the code based on Unit Test Cases
Create the build and pass on to the testing team.
Pit falls of Existing System.
o Most of the Bugs (which are of course nightmares of developer community) are discovered during the test cycles, rather than at unit test phase.
o Identifying the root cause of bugs becomes very difficult.o Code becomes tough to manage.o We can never be sure that every line of our code is tested.
TDD takes a different approach compared to traditional software development. Here a test case for a specific functionality is written rather than code. The functional code is written only to pass that test cases, one good thing is that duplication of code is avoided.
Rules of TDD are
o Test comes first.
o Write a functional code only if a test case fails.
o Make sure that your code is testing 100%.
o It always better to use Code coverage tools.
Initially, adopting TDD can be pain for developer community. Natural tendency of developers is to write code first and test next. More over they feel it’s too much of writing test cases rather coding. Developers are not used to do write and execute large no. of test cases. To implement TDD there are two requirements which are must.
o A faster complier.
o An automated tool for executing the test cases.
o Always use production data for your unit tests.
o In case if you don’t have production data on time, spend some time to create test data similar to production data.
Automated tool is a must for TDD. Without which executing a unit test case will be very difficult and becomes more time consuming. I have listed available tools for different languages in below section.
Benefits of TDD
o Biggest Benefit is verification. We can have exhausite set of automated unit test cases that can protect our system against defects.
o It is best suited to the systems where requirements are very dynamic.
o We can get simple and clear design.
o Code becomes loosely coupled and much easier to manager.
o Test code provides a complete documentation.
o It ensures that the system is free from defects.
o Avoids duplication of code.
o QA time is saved as many defects as many of bugs are worked out up front.
o Sytem what we develop exacts does it needs to do and no more.
o High quality unit tests can significantly augment the quality of code and can generate a tremendous amount of confidence in the integrity of tested code.
Originally written by
Sudheer Palyam http://spaces.msn.com/members/sudheerpalyam/PersonalSpace.aspx?_c=