History | Edit

XSpec is a behavior driven development (BDD) framework for XSLT and XQuery. XSpec consists of a syntax for describing the behavior of your XSLT or XQuery 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 File > New > XSLT Unit Test. You can also create an XSLT Unit Test from the contextual menu of an XSL file in the Project view. Oxygen XML Editor 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 master XSL document.

When you create an XSpec document based on an XSL document, Oxygen XML Editor uses information from the validation and transformation scenarios associated with the XSL file. From the transformation scenario Oxygen XML Editor uses extensions and properties of Saxon, improving the Ant scenario associated with the XSpec document.

Figure: New XSLT Unit Test Wizard

Running an XSLT Unit Test

To run an XSLT 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 XSpec for XSLT transformation scenario that is defined in the XSpec framework.

Testing a Stylesheet

An XSpec file contains one or more test scenarios. You can test a stylesheet in one of the following ways:
  • 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">
    • 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]" />
  • 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()" />
  • Test a template with a name.
    <x:scenario label="when creating a table">
      <x:call template="createTable">
        <x:param name="nodes">
        <x:param name="cols" select="2" />

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/expath/xspec/wiki/Writing-Scenarios.

Adding a Catalog to an XSpec Transformation

If your XSLT needs a catalog, you can add one to the XSpec transformation by doing one of the following:
  • If you are using a project in Oxygen XML Editor, create a catalog.xml file in the project directory. This catalog will then be loaded automatically.
  • Edit the XSpec for XSLT transformation scenario, go to the Parameters tab, and set the value of the catalog parameter to the location of your catalog file.