Test Driven Development

One of the most important practices of Agile development process is Test Driven Development (TDD). It is not a complex term to understand, TDD simply means you are aware of test cases before you actually start development of a piece of code. You are supposed to write test cases, automated test scripts, Junit test suite before you actually went on to write the real code.

Though the concept is simple, but in real world the implementation is not that easy. Why? Lets look at some of the key challenges.

Challenges for TDD

1. How can you create a test plan for something which does not even exist?
2. What if Requirement gets changed or modified? Instead of just making code change, we are making change to test plan as well. If we were creating tests after code completion, we will have saved ourselves from the trouble of making the changes to test plan.

Ok we have talked about the challenges, so why should we take so much pain and not just stick to the regular practice of writing test cases after writing the code.

Advantages of TDD

1. You can test the code implementation the moment you have written it without waiting for the test to be ready as the test was written before code.
2. Errors are caught at the early stage rather than propagating till late stages.
3. Test cases can be confirmed by business team, so that any discrepancy in the requirements can be figured out at an initial stage.
4. Most importantly, a TDD makes sure improvement in code quality. As the test cases are written in advance, it makes sure that all the code written passes the test before getting checked in.