XSLT Unit Test (XSpec)
XSpec is a behavior driven development (BDD) framework for XSLT, XQuery, and Schematron. XSpec consists of syntax for describing the behavior of your XSLT, XQuery, or Schematron code, and some code that enables you to test your code against those descriptions.
Creating an XSLT Unit Test
To create an XSLT Unit Test, go to Project view. Oxygen XML Developer allows you to customize the XSpec document when you create it. In the customization dialog box, you can enter the path to an XSL document or to a main XSL document.
. You can also create an XSLT Unit Test from the contextual menu of an XSL file in theWhen you create an XSpec document based on an XSL document, Oxygen XML Developer uses information from the validation and transformation scenarios associated with the XSL file. From the transformation scenario Oxygen XML Developer uses extensions and properties of Saxon 12.3, improving the Ant scenario associated with the XSpec document.
Running an XSLT Unit Test
To run a Unit Test, open the XSpec file in an editor and click Apply Transformation Scenario(s) on the main toolbar. This will run the built-in Run XSpec Test transformation scenario that is defined in the XSpec framework.
Testing a Stylesheet
-
Test an entire stylesheet - Testing is performed in a certain context. You can define a context as follows:
- Inline context, building the test based on a
string.
<x:scenario label="when processing a para element"> <x:context> <para>...</para> </x:context> ... </x:scenario>
- Based on an external file, or on a part of an external file extracted with an
XPath
expression.
<x:scenario label="when processing a para element"> <x:context href="source/test.xml" select="/doc/body/p[1]" /> ... </x:scenario>
- Inline context, building the test based on a
string.
-
Test a function:
<x:scenario label="when capitalising a string"> <x:call function="eg:capital-case"> <x:param select="'an example string'" /> <x:param select="true()" /> </x:call> ... </x:scenario>
-
Test a template with a name:
<x:scenario label="when creating a table"> <x:call template="createTable"> <x:param name="nodes"> <value>A</value> <value>B</value> </x:param> <x:param name="cols" select="2" /> </x:call> </x:scenario>
You can reference test files between each other, which allows you to define a suite of tests. For further details about test scenarios, go to https://github.com/xspec/xspec/wiki/Writing-Scenarios.
Adding a Catalog to an XSpec Transformation
- If you are using a project in Oxygen XML Developer, create a catalog.xml file in the project directory. This catalog will then be loaded automatically.
- Edit the
Run XSpec Test transformation scenario, go to the Parameters tab, and set the value of the
catalog
parameter to the location of your catalog file.