xsl-list
[Top] [All Lists]

Re: [xsl] Unit Testing

2014-09-20 05:19:22
On Sat, September 20, 2014 10:26 am, Michael Kay mike(_at_)saxonica(_dot_)com 
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(_at_)uottawa(_dot_)ca
...
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(_at_)mentea(_dot_)net
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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>