Changes

Jump to navigation Jump to search
338 bytes added ,  14:19, 20 July 2022
no edit summary
==unit:test==
{| width='100%'
|-valign="top"
| width='120' | '''Syntax'''
|{{Code|%unit:test}}<br/>{{Code|%unit:test("expected", CODE)}}
|-valign="top"
| '''Summary'''
|With this annotation, a function can be marked as unit test. It will be evaluated if a test report is created for the module in which this function is located.<br/><code>error</code> can be supplied as additional string argument. It is followed by <code>CODE</code>, which must be a valid [[XQuery 3.0#Expanded QNames|EQName]] string. If the function expression does not raise that error, the test will fail.
|-valign="top"
| '''Examples'''
|
{| width='100%'
|-valign="top"
| width='120' | '''Syntax'''
|{{Code|%unit:before}}<br/>{{Code|%unit:before(FUNCTION)}}
|-valign="top"
| '''Summary'''
|A function decorated with this annotation will be evaluated '''before each''' unit test as a separate transaction.<br/><code>FUNCTION</code> can be supplied as additional argument. It must be a valid [[XQuery 3.0#Expanded QNames|EQName]] string. If specified, the function will only be evaluated before a function with the given name is tested. This extension is e. g. helpful if the results of updates need to be tested.
|-valign="top"
| '''Examples'''
|
{| width='100%'
|-valign="top"
| width='120' | '''Syntax'''
|{{Code|%unit:after}}<br/>{{Code|%unit:after(FUNCTION)}}
|-valign="top"
| '''Summary'''
|A function decorated with this annotation will be evaluated '''after each''' unit test as a separate transaction.<br/><code>FUNCTION</code> can be supplied as additional argument. It must be a valid [[XQuery 3.0#Expanded QNames|EQName]] string. If specified, the function will only be evaluated after a function with the given name is tested.
{| width='100%'
|-valign="top"
| width='120' | '''Syntax'''
|{{Code|%unit:before-module}}
|-valign="top"
| '''Summary'''
|If a function is decorated with this annotation, it will be evaluated '''before all''' unit tests in the current module as a separate transaction.
{| width='100%'
|-valign="top"
| width='120' | '''Syntax'''
|{{Code|%unit:after-module}}
|-valign="top"
| '''Summary'''
|If a function is decorated with this annotation, it will be evaluated '''after all''' unit tests in the current module as a separate transaction.
{| width='100%'
|-valign="top"
| width='120' | '''Syntax'''
|{{Code|%unit:ignore}}<br/>{{Code|%unit:ignore(MESSAGE)}}
|-valign="top"
| '''Summary'''
|If a function is decorated with this annotation, it will temporarily be ignored by the test suite runner.
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|unit:assert|$test as item()*|empty-sequence()}}<br />{{Func|unit:assert|$test as item()*, $info as item()|empty-sequence()}}<br />
|-valign="top"
| '''Summary'''
|Asserts that the effective boolean value of the specified {{Code|$test}} is true and returns an empty sequence. Otherwise, raises an error. The ''effective boolean value'' of an expression can be explicitly computed by using the {{Code|fn:boolean}} function.<br/>The default failure message can be overridden with the {{Code|$info}} argument.
|-valign="top"
| '''Errors'''
|{{Error|fail|#Errors}} the assertion failed, or an error was raised.
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|unit:assert-equals|$returned as item()*, $expected as item()*|empty-sequence()}}<br />{{Func|unit:assert-equals|$returned as item()*, $expected as item()*, $info as item()|empty-sequence()}}<br />
|-valign="top"
| '''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-equal}} function]. Otherwise, raises an error.<br/>The default failure message can be overridden with the {{Code|$info}} argument.
|-valign="top"
| '''Errors'''
|{{Error|fail|#Errors}} the assertion failed, or an error was raised.
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|unit:fail||empty-sequence()}}<br />{{Func|unit:fail|$info as item()|empty-sequence()}}<br />
|-valign="top"
| '''Summary'''
|Raises a unit error. The default failure message can be overridden with the {{Code|$info}} argument.
|-valign="top"
| '''Errors'''
|{{Error|fail|#Errors}} default error raised by this function.
! width="110"|Code
|Description
|-valign="top"
|{{Code|fail}}
|An assertion failed, or an error was raised.
|-valign="top"
|{{Code|no-args}}
|A test function must have no arguments.
|-valign="top"
|{{Code|private}}
|A test function must not be private.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu