<< PreviousNovember 2004Next >>

Tuesday 09 November, 2004
#Unit Testing XSLT Stylesheets

Here's the proposal I sent for the ACCU Conference 2005.


XSLT is now a mature technology. It's widely used in web, document composition, electronic and print publishing applications, among others. Increasingly, XSLT styling isn't the last little bit at the end to create the HTML, but at the core of document creation and processing pipelines. Indeed it isn't uncommon, particularly in publishing applications, to have multiple XSLT transformation steps chained one after the other. XSLT stylesheets are getting larger and more complex, containing significant chunks of business logic.

XSLT, while addressing the specific issue transforming XML, is Turing complete. It's a real programming language, and people are doing real work with it.

Development is easier with automated testing. It's a given. That's why Ant integrates JUnit, and why C++ programmers up and down the land spend hours developing test harnesses because CppUnit just isn't quite right.

How do you test an XSLT stylesheet?

I'd like to present a tool for XSLT testing. Tests are described in an XML vocabulary. The test definitions are cranked through a set of XSLT stylesheets to generate Java source, more XML and yet more XSLT. The Java sources are JUnit test suites which drive the XSLT test procedure. It's all stitched together with Ant.

It's all quite neat from an exposition point of view. It's an application written in more or less equal parts of Java and XSLT. It uses multiple XSLT stages. It needs testing too :) While the code I have is in Java, it can be adapted to C#, C++ or any language where you have an XSLT processor and test harness available.

I think it could make quite a snappy 45 minute session.

Clever clogs will, of course, be aware of XSLTUnit - http://xsltunit.org/ - and it is undoubted rahter a cool piece of work. I'm aiming to be cooler though :) [added 9th Nov 2004]
anonymous said Unit testing is one of those things that everyone says is good, but secretly know it addresses about 10% of real life problems. It's good as far as it goes, but it's a long way from acomplishing what testing really needs to accomplish.

At lest this bloke says so - http://www.pyrasun.com/mike/mt/archives/2004/07/10/18.43.16/index.html [added 9th Nov 2004]

Automated unit testing is good, and you can't really argue with that. I'm not claiming it's the key to world peace. The article you link seems to suggest it's the root of all evil, but I don't see any substance in what he says. He sets up an extremely flimsy straw man, then beats the hell out of it without actually offering any alternative. w00t! Check his 3l33t debating skillz.

It's true that some things are easier to test that others. It's true the your definition of a "unit" can make a significant difference. Systems with a lot of state stashed in databases are a pain. GUIs of all sorts - web apps, Java, whatever - are also very difficult to test.

I'm doing a lot of work where significant things happen in XSLT, and so are more and more other people. Testing XSLT is a tedious, generally extremely manual, business. I'm just trying to make is a touch easier. [added 10th Nov 2004]

smellygit said I don't think that Unit testing is bad in anyway, but it clearly can't be used on it's own. What really matters is if the whole software suite does what the customer wants. A contractor at our place suggested adding unit tests to an existing large application, mostly for 'DTO' objects, along the lines of 'does this setter work'. This cheerfully ignored the fact that pieces of functionality were missing from the product.

I think what that geezer was saying was that some of the 'thought leaders' don't give enough emphasis to the end product vs. using there methodology.

I'm not saying that unit testng isn't a good idea, and if you are programming in XSLT then being able to test it like that is a good thing. Probably more so than it is with Java as the side effects are harder to see. [added 10th Nov 2004]

smellygit said s/there/their/ [added 10th Nov 2004]
The slides now available. [added 4th Oct 2005]

[Add a comment]