> Just confirm: while before-module and after-module are separate transactions, 
> within a single unit:test function that itself performs an updating function 
> there’s no way to then evaluate the result of the update as any asserts will 
> be in the same transaction.

Exactly.

> […] it would only make sense when you have exactly one unit:test in a module, 
> as unit:before/after is run for each test in the module.

You can also specify the name of a function along with %unit:before
and %unit:after [1]:

module namespace _ = '_';

declare %unit:before('b') function _:before-b() {
  prof:dump('before b')
};
declare %unit:test function _:a() {
  prof:dump('a')
};
declare %unit:test function _:b() {
  prof:dump('b')
};

Evaluating:
"a"
"before b"
"b"

If you want to simulate updates, another solution is to use the
copy/modify/return or update clauses [2]:

let $x := <x/> update {
  insert node 'x' into .
}
return unit:assert-equals(string($x), 'x')

[1] https://docs.basex.org/wiki/Unit_Module#unit:before
[2] https://docs.basex.org/wiki/XQuery_Update#Non-Updating_Expressions

Reply via email to