views:

102

answers:

5

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.

+1  A: 

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.

Grzenio
+1  A: 

See:

http://www.jenitennison.com/xslt/utilities/unit-testing/

and:

http://nwalsh.com/docs/presentations/xml2005/slides.pdf

and:

http://www.fgeorges.org/xslt/xslt-unit/

Dimitre Novatchev
Well done Google! ;-)
Duncan Smart
@Duncan-Smart: Yes, I don't remember links by heart. The only one really significant data that I haven't provided, is a survey by Tony Graham
Dimitre Novatchev
+2  A: 

If you are familiar with Apache Cocoon, you could use CoUnit which uses xslt-unit under the hood.

Testcases look like this:

<testcase id="03-reverse" ignore-whitespace="true">
  <input>
    <text-to-reverse> 
      The text in this element 
      <embedded-element/> 
      will be reversed.
    </text-to-reverse>
  </input>
  <expect>
    <text-to-reverse> 
      tnemele siht ni txet ehT 
      <embedded-element/> 
      .desrever eb lliw
    </text-to-reverse>
  </expect>
  <xslt src="reverse.xsl"/>
</testcase>
Jan Willem B
+1  A: 

I work on a project that uses XSL-T. We have a few data-driven tests running with visual studio. I also believe N-Unit has some data driven test features.

Meiscooldude
+4  A: 

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.

Kathy Van Stone