Dan Bunea recently posted on doing TDD with a web application. Since I’m currently cobbling together a similar TDD JSF example to use for a seminar in my organization I found Dan’s approach enlightening.

Dan begins at the completely at the front end writing a Selenium test against the initial page of an application where you add a user. He then builds the ASP pages in this case since it’s a .NET example and goes on to dig through the controller and business layers testing all the way to the database. He goes ahead and writes an integration test that tests the database during this process.

The integration test isn’t pure TDD, but I’ve taken the same approach in regards to my example so far instantiating an in-memory database with HSQLDB because I don’t really feel the need to rely on mocks to test my service and DAO objects.

I also differ in that I started at the controller and worked my way back, only developing the UI as a last step. My favorite approach is to try and ignore the GUI when doing development until the last step, though many people find that starting with the visual GUI layer is an easier starting point.

All in all a fairly good example of how you might approach TDD on a webapp.