Thanks—that’s very helpful.

My unit tests are doing what they need to for now but will definitely want to 
refine them with this new knowledge.

Cheers,

E.

_____________________________________________
Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
servicenow.com<https://www.servicenow.com>
LinkedIn<https://www.linkedin.com/company/servicenow> | 
Twitter<https://twitter.com/servicenow> | 
YouTube<https://www.youtube.com/user/servicenowinc> | 
Facebook<https://www.facebook.com/servicenow>

From: Christian Grün <christian.gr...@gmail.com>
Date: Wednesday, February 2, 2022 at 9:24 AM
To: Eliot Kimber <eliot.kim...@servicenow.com>
Cc: basex-talk@mailman.uni-konstanz.de <basex-talk@mailman.uni-konstanz.de>
Subject: Re: [basex-talk] Techniques for Unit Testing Updating Operations
[External Email]


> 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://urldefense.com/v3/__https://docs.basex.org/wiki/Unit_Module*unit:before__;Iw!!N4vogdjhuJM!SU4jXyuFok_Q006ccRre4Z1FgRQUxTg3o7EtB9sQO6XQHOr3EfrV7tn9osDaLac4rJ3Rag$<https://urldefense.com/v3/__https:/docs.basex.org/wiki/Unit_Module*unit:before__;Iw!!N4vogdjhuJM!SU4jXyuFok_Q006ccRre4Z1FgRQUxTg3o7EtB9sQO6XQHOr3EfrV7tn9osDaLac4rJ3Rag$>
[2] 
https://urldefense.com/v3/__https://docs.basex.org/wiki/XQuery_Update*Non-Updating_Expressions__;Iw!!N4vogdjhuJM!SU4jXyuFok_Q006ccRre4Z1FgRQUxTg3o7EtB9sQO6XQHOr3EfrV7tn9osDaLadhvMzKWA$<https://urldefense.com/v3/__https:/docs.basex.org/wiki/XQuery_Update*Non-Updating_Expressions__;Iw!!N4vogdjhuJM!SU4jXyuFok_Q006ccRre4Z1FgRQUxTg3o7EtB9sQO6XQHOr3EfrV7tn9osDaLadhvMzKWA$>

Reply via email to