Introducing Test Driven Development
TDD is a development technique based on a simple idea, that is, no code should exist without test coverage.
In order to pursue this goal, TDD inverts our point of view. Instead of developing code, and then writing a unit test to cover its testing, you should start writing a test case. Of course, initially, the test case would intentionally fail while invocating empty or incomplete functions. However, you will have a clear goal, that is, your piece of code is complete when all tests are satisfied.
Starting from the end, you clearly define the boundaries of your software and the extent of its functions. Then, you run the tests, which will all fail. You keep developing the features, piece after piece, until all of the tests are satisfied. Finally, you move to the next piece of code (or class or package)—it's that simple.
Remember that this approach doesn't necessarily guarantee any particular quality or elegance in your code...