Test driven development (TDD) is an advanced technique which is an evolution of the test first programming concept in extreme programming.
In TDD the programmer first writes the test for a particular routine before actually writing the routine itself. naturally the test will fail because there is no working code that satisfies the test conditions.
the programmer then writes just enough code to pass the test(Adhering to SOLID, YAGNI and KISS principles).
after the test passes successfully the programmer then returns to the production code in order to refactor it by Changing the code to remove duplication and to improve the design while ensuring that all tests still pass.
this cycle is called Red, Green, Refactor and is done repetitively until the piece of software being developed is complete.