[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] junit test... for xslt2?


Subject: Re: [xsl] junit test... for xslt2?
From: Dave Pawson <davep@xxxxxxxxxxxxx>
Date: Mon, 08 Mar 2010 10:45:33 +0000

On 08/03/10 10:06, Florent Georges wrote:

A couple of remarks here.

   If we speak about the result of a "whole transform", I tend to
see it as defined by an input and an output, so the result can be
tested against an expected output.  As a few values can not
depend on the input (like generate-id()) we need a mechanism to
compare two documents (where we can say: "do not compare text
nodes with whitespaces", or "do not compare the value of the
attributes 'id'").

This is where I'm hoping 'structure checking' is possible using xpath only? The poor mans xml diff. I wonder how well Schematron fits this model.




But then this is more "functional testing" than "unit testing".

Not sure what I'd like to call it!



For unit testing, I'd say one component has only a few
responsibilities on the result it produces.  It does not always
define its whole output.  Some parts are the responsibility of
other components (like called functions or other template rules).
And in unit testing, I think assertion expressions (what I think
you mean by "you just need to execute XPaths against it") is
really more convenient than comparing two entire trees.

This backs up your idea of keeping templates 'simple' or single purpose? Surely the difference is simply one of 'level'? Test one template vs test a tree of templates?




Here is a simplified exerpt of a test suite for the EXPath HTTP Client:

     <t:call function="http:send-request">
        <!-- some param here... -->
     </t:call>
     <t:expect test="count($t:result) eq 2"/>
     <t:expect test="$t:result[1] instance of element(http:response)"/>
     <t:expect test="$t:result[1]/xs:integer(@status) eq 200"/>
     <t:expect test="$t:result[2]/*">
        <pass>...</pass>
     </t:expect>


Good example of a test 'group', each part being a simpler test (atomic test?)

Another good example where you are concerned about text content (the value 200 is pretty essential), where in other cases you really don't
care about content, but elements / attributes *must* be present or missing.





regards


--
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk


Current Thread
Keywords