Changes

Jump to navigation Jump to search
1,243 bytes added ,  09:09, 30 April 2015
no edit summary
|-
| width='120' | '''Syntax'''
|{{Code|%unit:test}}<br/>{{Code|%unit:test("expected", ERRORCODE)}}
|-
| '''Summary'''
|With this annotation, a function can be marked as unit test. It will be evaluated whenever if a test report is created for the module in which this function is located.<br/>If an optional <code>error </code > can be supplied as additional string argument. It is specified and if 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.|-| '''Examples'''|* The following test does will be successful, as it does nothing (and, hence, nothing wrong):<pre class="brush:xquery">declare %unit:test function local:void() { () };</pre>* The following test will be successful, as the function body will raise <code>err:XPTY0004</code>:<pre class="brush:xquery">declare %unit:test('expected', "err:XPTY0004") function local:add() { 123 + 'strings and integers cannot to added'};</pre>
|}
|-
| '''Summary'''
|A function decorated with this annotation will be evaluated '''before each''' unit test.<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 specified as argument, it tested. This extension is e. g. helpful if the results of updates need to be tested.|-| '''Examples'''|* The first function will only be evaluated before that the actual test:<pre class="brush:xquery">declare %updating %unit:before("local:check") function local:before-check() { db:create('test-db')};declare %updating %unit:test function.local:check() { unit:assert(db:exists('test-db'))};</pre>
|}
|-
| '''Summary'''
|A function decorated with this annotation will be evaluated '''after each''' unit test.<br/><code>FUNCTION</code> can be supplied as additional argument. It must be a valid [[XQuery 3.0#Expanded QNames|EQName]] string. If a function name is specified as argument, it the function will only be evaluated after that a functionwith the given name is tested.
|}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu