I was recently reminded of this by Scott Bellware on this hanselminutes episode.
It’s easy to fall into the trap of thinking about TDD as a testing technique. I mean, Test is the first word in TDD. And normally you hear it talked about as Test Driven Development, not Test Driven Design. Since most development going on is probably not Greenfield, but is in maintenance/support mode, I’d bet that those involved with most applications think that the design phase is “done”. Even when new features are being added to an existing application/platform, it’s not like you’re starting from scratch, you’re usually bolting things on to existing functionality.
And therein lies a pitfall. Most people would probably be more concerned with not breaking existing functionality, as opposed to letting TDD help design the new functionality.
Another pitfall comes from that first word, Test. Don’t get me wrong, I love tests. However, it is quite possible that you follow the red/green/refactor methodology of writing tests and still come out with poorly designed code. This comes from what I like to call the “Mother of Invention Principle”. Yeah, I just coined a principle. Basically, one of the ideas of TDD is that there should be no new code added until it is required by at least one test. So, if you follow this principle, then you should technically have 100% code coverage when finished.
Unfortunately, 100% code coverage isn’t useful. Anything but 100% would be useful (but more on that in another post.) Maybe the tests were poorly designed. Maybe the tests are spot on, but they require huge amounts of setup and teardown for each test. Sure, it’s tested, but is it designed well?
This kind of thinking, about “fully” tested code, sure make TDD a good sell to management and QA, but alas, that’s not what TDD was meant for.
Anyway, I won’t belabor the point, listen to the podcast. Scott and Scott talk about this much more eloquently than I can.