I have just recently discovered how much I enjoy developing code the TDD way: I feel I have much more control over the direction the development is going. Whereas before I spent a lot of time designing data structures and algorithms up front, now I start small and “grow” my code organically. After every red/green/refactor cycle I have code that does something. It feels like my code is a living thing and I am directing where it should grow. I don’t know if that’s how everyone feels when they get into TDD, but this is my experience. And it strikes me that this is so similar to how successful free software projects are grown rather than designed.
However, now that I have got a hang on the test-driven development, I am beginning to wonder what its limits are. It seems to be quite useful for developing functional code: feed this input to that function, and you get this result. But this is just a small part of what software development is about. What about GUI development, networking, database development, web applications? What is your experience? Have you ever tried TDD with any of these types of development? Do you know of any tools or frameworks? Can you recommend any articles or books?
“What about GUI development, networking, database development, web applications?”
Why wouldn’t it work?
GUI. The only thing TDD can’t do well is evaluate the “look” of the interface. But it can evaluate the behavior. If you did your design well (separating model, view and control), you can test the control and model easily as TDD. view, however, is more difficult to write tests for. (“assert that the button is below the field” isn’t sensible.)
Networking. Not sure what this means. However, defining RESTful web services works out very nicely when done via TDD. Define the URI’s, write test cases, and then build the services that provide expected responses.
Web Applications. The Django web framework directly supports TDD for development. They have unit tests for the web data model and control layers. Plus, they have unit tests for the HTML page presentation and behavior.