Thanks to Rod Johnson’s book, I now have a good solid method for performing test-driven development. Previously, it was always cumbersome and required too much work to easily convince others. His method is simple:
- Write an interface for the class (You are coding to interfaces, right?)
- Use an IDE or script to create a dummy implementation of the interface with methods that either:
- do nothing
- return null
- throw an UnsupportedOperationException
- write a failing test that checks for the desired behavior
The test will now compile and run. (Obviously it will fail!) Such a simple procedure makes test-driven development much more palatable. Thanks Mr. Johnson!
If you are not familiar with JUnit, now is the time to check it out.
I also suggest reading the book, it is very worthwhile. (“export one-on-one J2EE Design and Development”)