TDD, or in full Test Driven Development, is an approach to development in which we start from writing tests.
Before we write the code for a particular functionality, we think about exactly what result we expect when triggering a particular action and put it in a test beforehand.
An example of this is a date mapper functionality. When you pass certain input to the mapper, you expect it to come out in a different format.
$mappedDate = DateMapper:AmericanDatetoDefaultDate('05/27/2005');
self::assertEquals('2005-05-27', $mappedDate);
When we run this test, of course it will fail, and that is what it is supposed to do.
The next step is to write minimum code to make the test pass. Then we run the test again and repeat this process until all assertions are successful and thus all expectations have been met. Once the test has run successfully, we look at how we can optimize or simplify the code. If the test is successful with minimal code, then we write out the next unit test.
This continuous process can be represented as follows: