开发者

How do I perform automated testing of XSLT stylesheets?

I have some increasingly complex XSLT stylesheets and it would be helpful if I 开发者_如何学Ccould 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.


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.


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.


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/


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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜