Is TDD worth the effort? Andy Dwelly tried applying my TDD screencasts to his iOS coding. Here’s what he writes in Some notes on Test Driven Development:
At first progress was almost painfully slow.
Yup. It seems like there’s a lot to learn. The real barrier, I think, is that there is a lot to unlearn. And so, when you first get started with Test Driven Development, your productivity will take a big hit. This is normal! But if you’re willing to press through the learning curve, your productivity will increase again — in ways you may not have experienced before…
TDD: Immediate Benefits!
I would normally expect to write the final line and then fire up the debugger to get it to actually work.
Except that it did just work.
I experience this fairly regularly, even when I TDD a new view controller.
I think at this point, if I’d been asked anything about the issue of code quality I would have claimed that the actual code produced was marginally better. My TDD code certainly handled errors and failures better, but had poorer information hiding and some dependency injection that I would not normally have bothered with.
Then my tests found a bug that I don’t think I would have spotted until the code hit the field.
Do the math: What is the cost of a fixing a defect vs. preventing a defect? Even though TDD takes more time up-front (when it’s just the developer’s time), it reduces time later (when more people are involved). I think there’s enough evidence out there to make this claim: Once you make it over the learning curve, your time-to-market will be the same — but with many more benefits!
I’m still of the view that trying to do a lot of UX tests using TDD is hard.
What Andy hasn’t experienced yet is the real powerhouse that TDD enables: refactoring. To me, this is the greatest benefit of Test Driven Development. It’s a shift of emphasis, from “prevent bugs” to “empower change.” And that’s why I’m vigilant about unit testing view controllers, down to the nib connections. Where some people say, “I don’t think that last bit is worth the effort,” my reply is, “It’s often not that hard. Why would you turn down the chance to automatically check your code?”
So Andy is still early in his iOS TDD journey. He’s still approaching it with some skepticism. But it didn’t take long for him to experience some of the benefits! Go read his account.
Then I’d like to hear from you: Is TDD worth the effort? What are your questions / concerns / reservations / experiences?