XQuery 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 XQuery Unit Test
To create a XQuery Unit Test, go to
. This is simple document template to help you get started.Running an XQuery 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 an XQuery file
An XSpec file contains one or more test scenarios.
Example:
module namespace functx = "http://www.functx.com";
declare function functx:capitalize-first
($arg as xs:string?) as xs:string? {
concat(upper-case(substring($arg, 1, 1)),
substring($arg, 2))
};
hello
as a parameter. The expected value that should be returned by the
function (the string Hello
) is contained in the @select
attribute of the x:expect
element.<x:scenario label="Calling function capitalize-first">
<x:call function="functx:capitalize-first">
<x:param select="'hello'"/>
</x:call>
<x:expect label="should capitalize the first character of the string" select="'Hello'"/>
</x:scenario>
For more details about how to write XQuery tests and various samples, see https://github.com/xspec/xspec/wiki/Getting-Started-with-XSpec-and-XQuery.