Test-Driven Development
What is Test Driven Development?
Test Driven Development (TDD) is a process for building software that helps to guide software development by focusing on testing. It involves writing tests before writing any code so that you are then writing code to make the test pass. It ensures that you know what needs to be done before you start and helps to keep you on track as you are only focusing on implementing one piece of functionality.
The steps of TDD are:
- 1. List all functionality for new feature
- 2. Write a test for one of the new pieces of functionality
- 3. Run all tests - the new one should fail
- 4. Write the simplest code to pass the test
- 5. Run all tests - they should all pass
- 6. Refactor as needed whilst continuing to run tests
- Repeat Steps 2 - 6 until all pieces of functionality have been implemented into tests.
Following these steps ensures that a program is built piece by piece with each piece being well tested so that if new code breaks any older parts of the program you will know as soon as you run a test and then you don’t have to spend as much time debugging to find out if new code has caused old tests to fail.