Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I perform automated testing of XSLT stylesheets?

I have some increasingly complex XSLT stylesheets and it would be helpful if I could run some tests on them as part of my CI build process, and even use TDD to develop them in the first place. I'm currently using Visual Studio to run fragments of XML through the stylesheets and I am manually checking the results.

What would everyone recommend for this? Ideally it would be easy to integrate into CruiseControl.NET and/or MsBuild.

like image 815
GraemeF Avatar asked Jun 25 '10 12:06

GraemeF


2 Answers

What I have done is used my standard unit testing system with a good library for testing output. At my current project, the output is XHTML and I am using JUnit and xml-unit. At a previous project, the output was XSL-FO and I used python-unit and xmllib. This allows me to build the XSLT gradually (using TDD) by having a single test check only part of the output. If the output is text, however, I might compare the entire result. I used my current unit testing software for two reasons. First, I was familiar with it so it was faster to get started. Second, it was very easy for the testing to be automated with the build if it was already using the type of test the build was expecting.

like image 181
Kathy Van Stone Avatar answered Nov 12 '22 18:11

Kathy Van Stone


I think I would write unit tests for them in your programming language of choice (e.g. C#). Have a collection of input xmls and corresponding expected outputs and just run the xsl on these and make sure they match the outputs. I am not sure if there is a smarter way of doing the testing.

like image 2
Grzenio Avatar answered Nov 12 '22 17:11

Grzenio