Explain TDD (Test Driven Development)?
What is Test Driven Development (TDD) and what are its advantages or disadvantages?
I got introduced to the TDD approach of software development a few years ago. I first did not like the concept of Test Driven Development; because it looked liked much of an overhead. However, after working on a large project here at CrazyEngineers, I've found out that TDD has a ton of advantages over regular development.
The TDD Approach
The TDD approach differs from regular development approach in a fundamental way. In regular development, the software developer typically determines the feature to be implemented based upon the product requirements and heads over to coding it right away.
The testing part is typically done after the feature has been implemented. The result of this approach is that the bugs are often discovered after the feature has been implemented and the developer has to back-trace the code to debug it.
However, in TDD (Test Driven Development), the developer will first write a test case for the feature and build unit tests.
A unit test will simply determine the flow that should take place for the user. The idea is -
- Write the test case and relevant unit tests
- Run the test and let it fail
- The developer runs the failed test over and over to look at the output and fix the reported errors.
That looks like too much work, right?
But think about it in this way - the developer does not have to really care about the flow anymore - and is guided by the tests throughout the feature implementation.
Let me know if you'd like to have a real example of TDD. I'll create one to explain this in detail.
PS: TDD is typically a development approach and not related to 'software testing' directly.