XTC, by Florent Georges, is available from http://www.fgeorges.org/xslt/xslt-unit/. XTC is an XSLT 2.0 framework that is capable of testing both XSLT 2.0 and XQuery. A single test comprises an assertion of the expected result followed by a sequence constructor, as in the following example from the XTC web site that illustrates testing a function from the stylesheet under test:
<t:tests> <t:title>hello-world()</t:title> <t:test> <t:expect select="'Hello, world!'"/> <xsl:sequence select="hw:hello-world()"/> </t:test> </t:tests>
The sequence constructor – a single xsl:sequence in this case, though it could be more complicated – is compared for equality with the expected result. Alternatively, the expected result could be written as an XPath expression to evaluate or, when used with Florent’s ‘error-safe’ extension for Saxon, an assertion of an error that should be thrown when evaluating the sequence constructor.
The XML file containing the tests is transformed into a test stylesheet that imports the stylesheet being tested. That stylesheet, when run, ignores its XML input and runs named templates corresponding to the tests in the original test XML file.
The output of the test stylesheet is an XML file that can be transformed into a HTML report. Figure 1 shows the sample report from the XTC web site.