A while ago I put together a framework for unit testing XSLT. I’ve been using that for a couple of years and it’s been OK, but then I started playing with Ruby on Rails, and testing with RSpec: a framework for Behavioural Driven Development (BDD). It got me wondering what BDD for XSLT would look like.
And so I put together XSpec. To use it, you write scenarios in an XSpec description documents and test your stylesheet against those scenarios using a script (I have mine integrated into Oxygen, so I just hit a button and get a test report on my stylesheet).
What’s the difference between this and the various other XSLT unit testing frameworks out there? Basically, it’s the BDD-ness: the focus on creating a human-readable description of the desired behaviour of your stylesheet rather than simply a bunch of executable tests. I find XSpec fits better with how stylesheets are designed than the unit-testing framework I developed previously. Plus I’ve built in features that I’ve found useful in RSpec and through experience, such as the ability to nest scenarios and focus on particular tests, suppressing everything else. I also hope that it will (eventually) be executable via XProc, which will get around some of the problems with testing XSLT with XSLT whilst still being declarative and programming-language neutral.
I’ve been using XSpec on my most recent XSLT project, and it’s been a major asset. I currently have around 250 tests, which take just a few seconds to run, but make me feel extremely secure that the changes I make don’t mess up anything that matters. It’s taken great discipline, especially in the early stages, to make the development truly driven by the behaviour I desire (in other words, to create the tests before I write the code), but I’m reaping the rewards now.
Anyway, XSpec is in Google Code, so you can try it out, and even help with its development if the fancy takes you.