Re: [xsl] Unit Testing

Subject: Re: [xsl] Unit Testing
From: "Tony Graham tgraham@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 20 Sep 2014 10:18:58 -0000
On Sat, September 20, 2014 10:26 am, Michael Kay mike@xxxxxxxxxxxx wrote:
> Are you familiar with XSpec?

XSpec is at https://code.google.com/p/xspec/

> We had an interesting discussion the topic of testing at the XML Summer
> School yesterday. Personally I prefer to test at the level of a complete
> stylesheet, rather than trying to test individual templates and functions.
> My main reason for this is that it leaves you more freedom for
> refactoring: if I change the way a stylesheet is implemented without
> changing its external effect, I don't want to have to rewrite lots of
> tests.

XSpec can use external XML files as input to tests, so you can run
complete documents and make assertions about the result.

If you just want to check that nothing significant has changed, you can do
what I've done several times (despite being on the XSpec project) and
write a stylesheet that takes two XML files, elides the timestamps and
other variable information, and runs deep-equal() on the cut-down
versions.  (If comments below the root are significant, you need to at
least also count comments.)

With a bit more effort, you can write a stylesheet to do that on all the
files in two directories, and it doesn't take much to automate that and to
automate the zipping and unzipping of timestamped sets of reference files.

If your reference set is small enough (and didn't include timestamps in
the output files), you could check your reference files into a version
control system, overwrite them when you run your tests, and let the
version control system tell you when things have changed.

> On 19 Sep 2014, at 15:19, Bertrand Lefort blefort@xxxxxxxxxx
...
>> I am wondering how to make unit testing with xslt 2. I am using saxon
>> with ant.

There's a 'build.xml' [2] in the XSpec SVN that somehow doesn't make it
into the bundled distributions that has both a 'xspec' target and a
'xspec' macrodef for making it easy to run XSpec from Ant.

There's also <jxsl/> [1] for using XSpec with JUnit.

Regards,


Tony Graham                                         tgraham@xxxxxxxxxx
Consultant                                       http://www.mentea.net
Chair, Print and Page Layout Community Group @ W3C    XML Guild member
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
Mentea       XML, XSL-FO and XSLT consulting, training and programming

[1] https://code.google.com/p/jxsl/wiki/XslUnitTesting
[2] https://code.google.com/p/xspec/source/browse/trunk/build.xml

Current Thread