XML::Validator::Schema and Test Driven Development

samtregar on 2003-09-24T03:21:01

I've finally gotten my hands dirty with XML::Validator::Schema. I'm using it as a test case to try out Test Driven Development, as I learned it from Test Driven Development: By Example.

So far it's been a mind-bending trip. If you don't know, TDD is about writing tests first, coding just enough to make all the tests pass and then refactoring to reduce duplication. The result is hopefully lean, well-tested code with less risk of failure and less wasted effort.

I'm utterly surprised by just how much refactoring I've been doing. I've added sub-modules, removed them and added them back. I've removed more methods than I've written. As each test case goes in the entire architecture of the module comes up for review. It's a refreshing process, and the results so far are pretty good. XML::Validator::Schema is probably 30% of the way to replacing Xerces/C++ on my latest project, after only 3 days of development.

In some ways this is the ideal TDD project because I have no idea what the architecture of an XML Schema validator should look like. As I add new test cases I can evolve the design to handle the added complexity. And with a standardized file format like XML Schema I've got a wealth of potential test cases at my fingertips and little opportunity to write bad tests.

The only downside I've found so far is that I'm not writing very much developer-focused documentation. Knowing that the code will likely change radically very soon puts a damper on writing baroque descriptions of how things work. I guess I'll find out how much of a problem this is when I get to maintain the code later...

-sam