What is Test Driven Development?
Test Driven Development (TDD) is a method of software development that uses testing for certain functionality to reduce the amount of code that needs to be written. Using TDD techniques, software testers (or developers themselves) write specific tests for certain functionality in the software being developed, and then run these automated tests to determine if the code passes or fails. New code is only written for those functions that fail the tests, speeding up the development process and shortening time to market.
Why is TDD important?
The main benefit of TDD is the large number of tests written for different functionality in the software, which results in more testing being done, and therefore fewer defects in the final product. Other benefits include:
- TDD works well with an iteration-driven development framework approach like Agile, because tests are continually developed and run for new and existing functionality as part of the process.
- TDD helps developers better understand the requirements of the software from the customers’ perspective, because tests are often written to test functionality specified by the customer.
- The iterative approach of TDD creates a quicker feedback loop, so development can progress faster and developers can also get more positive reinforcement for the stability and functionality of their software more often.
How is TDD done?
There are generally five steps that are followed in any TDD process:
- Understand the requirements: developers are tasked with reading and understanding the feature, functionality or issue required by the customers;
- Write the test: TDD is usually done at the unit level, so unit tests are written for specific functionality as stipulated in the requirements;
- Write the code: code is only written after the test is ready, and once written, the test is run to determine whether the code passes or fails the requirements;
- Clean the code: if the test fails, the code needs to be rewritten until it passes, but if it passes, code can still be optimised before proceeding with the next function; and
- Repeat the process: since TDD is iterative, the process is repeated until all unit testing on the product is done, and development can proceed to completion.