I'd also like to throw it out there that testing can be especially helpful when writing code against known problems. Some benefits are:
- Since you already know the problem domain, your test writing will be extremely quick and effortless, so the benefit of having that test in the first place far outweighs the time/effort invested in writing them.
- In dynamic languages especially, typos are what kills you in this situation. Testing will quickly catch 'em as you program.
- Finally, testing will force you to think more about the edge cases, since implementation is a straight-forward process. Thus, you'll spend less time later doing QA and have an overall more polished feature.
After a few successful demos you're given an tight deadline to "finish things", so you have no choice but to polish up the prototype and ship it.
The moral: code that was written to be thrown away often isn't. You can still write code quickly, and take shortcuts (such as skipping tests), but recognize that you'll probably be working on that code for a very long time and may regret your decisions later.
The central point I am trying to make is that it seems wasteful to spend time writing tests for code that may soon be deleted.
There is no need to write tests for fast moving objects and for this kind of work TDD is a waste of time in my opinion. But for core infrastructure this makes sense.
But driving blind all the time is not a good idea on the long run.
If I'm cranking out a prototype to show a customer then I don't want to spend precious time writing tests for code that stands a good chance of being thrown away at the start of the next iteration.
Tests often do need to be written, but the best time to do this seems like an unsolved problem to me.