Test Driven Development is a software development approach developed by Kent Beck. I personally find this technique very useful to deliver a good quality in your software, which must be always the goal for a good engineer, or also if you have signed a concrete test coverage with the client in the project contract. It is based on a very short development cycle which would be like the following:
Having created a test class and a test method to test a feature:
- Write enough test code to make the test fail.
- Write the minimum production code to pass the test.
Iterate between 1 an 2 while the feature is not ready. That would be the basic cycle. Of course we could also add refactoring to the equation, that would result in:
- Write enough test code to make the test fail.
- Write the minimum production code to pass the test.
- Refactor test code.
- Refactor production code.
The last one would be a more complete cycle, and although steps 3 and 4 wouldn’t be always necessary, it is important only to do one thing at a time and to respect the order. In other case we could introduce mistakes. Why is it important to write only production code when we have a test? Because otherwise you could forget that test, so simple.
To put this in practice I recommend you the video “Getting started with TDD in JAVA using Eclipse” from Brett L. Schuchert. I have personally done it and I think it will help you to grasp a good comprehension from the basics of this technique. I hope you enjoy it.