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.
I am wondering what framework/language you use for your TDD if you have not yet hit the most obvious parts of where it is difficult:
GUIs - Certain environments and platforms, specifically, Windows Forms and ASP.NET web forms, suffer from practical untestability, because there is no easy way to isolate or mock their behavior. This is one of the main driving forces of ASP.NET MVC, for that matter.
Persistence - Any sort of persistence, whether it be disk storage, connection to a database, to a network, or some other form of external system would be a limitation, as all of them are persistence tests which depend too much on the state of an external component to succeed. These integration tests then are considered fragile tests. Mocking is used to mitigate the impact of such external systems.
Adoption - Even if you are well versed in TDD, it's an uphill battle trying to get other developers -- much less whole development shops -- to use it. Many just don't see the benefit; they are easily turned off by the initial steep learning and productivity curves. You will encounter cases wherein you're the only one practicing TDD in your project and even if you enforce it the other developers will introduce low-quality, senseless tests. This non-technical reason is the biggest hurdle to using TDD in real-life production systems that I have faced, and it's a painful realization when you're quite aware of the benefits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With