Changes

Jump to navigation Jump to search
72 bytes added ,  11:54, 27 July 2020
m
Text replacement - "==%" to "=="
=Introduction=
The more complex a software application grows, the more error-prone it gets. This is why testing frameworks have been developed, which provide a standardized, automatized automated way for of testing software. The [httphttps://en.wikipedia.org/wiki/XUnit XUnit] frameworks (such as SUnit or JUnit) allow testing of atomic unit units of a program, such as single functions and algorithms.
This module borrows heavily from the existing frameworks: it provides various annotations for testing XQuery functions. Unit functions are provided to assert the validity of arbitrary conditions expressed in XQuery and to raise errors whenever a condition is not satisfied. Some additional functions exist to run all unit tests of the current module or a set of specified library modules.
=Annotations=
==%unit:test==
{| width='100%'
|-
|
* The following test does will be successful, as it does nothing (and, hence, nothing wrong):
<pre classsyntaxhighlight lang="brush:xquery">
declare %unit:test function local:void() { () };
</presyntaxhighlight>
* The following test will be successful, as the function body will raise <code>err:XPTY0004</code>:
<pre classsyntaxhighlight lang="brush:xquery">
declare %unit:test('expected', "err:XPTY0004") function local:add() {
123 + 'strings and integers cannot to be added'
};
</presyntaxhighlight>
|}
==%unit:before==
{| width='100%'
|
* The first function will be evaluated before the actual test:
<pre classsyntaxhighlight lang="brush:xquery">
declare %updating %unit:before("local:check") function local:before-check() {
db:create('test-db')
unit:assert(db:exists('test-db'))
};
</presyntaxhighlight>
|}
==%unit:after==
{| width='100%'
|}
==%unit:before-module==
{| width='100%'
|-
|}
==%unit:after-module==
{| width='100%'
|-
|}
==%unit:ignore==
{| width='100%'
|-
|-
| '''Errors'''
|{{Error|UNIT0001fail|#Errors}} the assertion failed, or an error was raised.
|}
|-
| '''Summary'''
|Asserts that the specified arguments are equal according to the rules of the [https://www.w3.org/TR/xpath-functions-31/#func-deep-equal {{Code|fn:deep-equalsequal}} function]. Otherwise, raises an error.<br/>The default failure message can be overridden with the {{Code|$info}} argument.
|-
| '''Errors'''
|{{Error|UNIT0001fail|#Errors}} the assertion failed, or an error was raised.
|}
|-
| '''Errors'''
|{{Error|UNIT0001fail|#Errors}} default error raised by this function.
|}
==Query==
<pre classsyntaxhighlight lang='brush:"xquery'">
module namespace test = 'http://basex.org/modules/xqunit-tests';
()
};
</presyntaxhighlight>
By running {{Code|TEST tests.xqm}}, the following report will be generated (timings may differ):
==Result==
<pre classsyntaxhighlight lang='brush:"xml'">
<testsuites time="PT0.256S">
<testsuite name="file:///C:/Users/user/Desktop/test.xqm" time="PT0.212S" tests="8" failures="4" errors="1" skipped="1">
</testsuite>
</testsuites>
</presyntaxhighlight>
=Errors=
|Description
|-
|{{Code|UNIT0001fail}}
|An assertion failed, or an error was raised.
|-
|{{Code|UNIT0002no-args}}
|A test function must have no arguments.
|-
|{{Code|UNIT0003private}}|A test function is must not public.|-|{{Code|UNIT0004}}|An annotation was declared twice.|-|{{Code|UNIT0005}}|An annotation has invalid argumentsbe private.
|}
=Changelog=
 
;Version 9.0
 
* Updated: error codes updated; errors now use the module namespace
;Version 8.0.2
 
* Updated: (expected) errors are compared by QNames instead of local names (including namespaces).
;Version 8.0
 
* Deleted: {{Code|UNIT0006}} (ignore results returned by functions).
* Added: [[#unit:fail|unit:fail]], 0-argument signature.
This module was introduced with Version 7.7.
 
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu