Database Reference
In-Depth Information
<id>{id:generate()}</id>,
$record/node()
}
</record>
};
(: Unchanged remaining code omitted for brevity... :)
The %test:args annotation provides values to the function's arguments when
the test case is run. If your function takes more than one argument, you can sup‐
ply them one after another—for example, %test:args("arg1", "arg2",
"argN") .
The %test:assertError annotation asserts that, for the previously provided
args , the function must throw the error (code) that is named—in this case,
id:ERR-PRESENT .
OK, so now we have seen how to annotate our function with some parameters for
our test case and an assertion about the expected result of executing that function
using those parameters. However, we have not yet run our test case—so how can we
actually have eXist execute our test case and return a report of whether it succeeded
or failed? Well, of course, we have to write another little bit of XQuery! We'll create
an XQuery main module so we can directly execute it, and from this XQuery we will
invoke XQSuite against the functions in our XQuery library module, id-1.xqm . Such
an XQuery main module is known as a test runner (see the file test-runner.xq ) and is
demonstrated in Example 16-3 .
Example 16-3. Test runner XQuery (test-runner.xq)
xquery version "3.0" ;
import module namespace inspect = "http://exist-db.org/xquery/inspection" ;
import module namespace test = "http://exist-db.org/xquery/xqsuite" at
"resource:org/exist/xquery/lib/xqsuite/xqsuite.xql" ;
let $ modules := (
xs:anyURI ( "/db/apps/exist-book/chapters/advanced-topics/xquery-testing/id-1.xqm" )
)
let $ functions := $ modules ! inspect:module-functions (.)
return
test:suite ( $ functions )
We import the eXist XQuery inspection module, so that we can reflectively find
all the functions in our module we wish to test.
Search WWH ::




Custom Search