testing of updating functions in basex
Tuesday, 17 November 2020 · 3 messages · last reply 18 Nov 2020
D
dudzikp17 Nov 2020 13:18 #
Dear all,
I have not found a way to make basex unit module to test updating functions. I have a function site:add-movies which results in several
db:add instructions. I try to achieve something like:declare %unit:test %updating function test-site:download-movies() {
let $result :=
site:add-movies(
$test-site:site-db,
test-site:fake-fetch-file#1,
7
)
return unit:assert-equals(1, 1) (: here I am going to check if db contains expected elements :)
};But let command is not valid for updating expression. Basex docs mention something about
update:output and update:cache which may be of some use here but no exhaustive example is given for.
Anyone had similar problem?
BRCG
Christian Grün17 Nov 2020 19:41 #
Dear BR dudzikp,
You can place your actual test your assertion in a second function with the %unit:after annotation. Another solution is to perform your update in a %unit:before function and test the result in the main function. See [1] for an example.
Cheers,
CG
[1] https://docs.basex.org/wiki/Unit_Module#unit:before
Quoted text · dudzikp at yahoo.com · 23 lines
On Tue, Nov 17, 2020 at 1:20 PM dudzikp at yahoo.com <dudzikp at yahoo.com> wrote: > > Dear all, > > I have not found a way to make basex unit module to test updating functions. I have a function site:add-movies which results in several db:add instructions. > I try to achieve something like: > > declare %unit:test %updating function test-site:download-movies() { > let $result := > site:add-movies( > $test-site:site-db, > test-site:fake-fetch-file#1, > 7 > ) > > return unit:assert-equals(1, 1) (: here I am going to check if db contains expected elements :) > }; > > But let command is not valid for updating expression. Basex docs mention something about update:output and update:cache which may be of some use here but no exhaustive example is given for. > > Anyone had similar problem? > > BR
D
dudzikp18 Nov 2020 09:04 #
That perfectly suits my needs. I misnoticed the possibility for the "%unit:before" to be invoked before one single unit function. Thanks Christian for your fantastic product!
BR
Quoted text · Christian Grün · 1 line
On Tuesday, November 17, 2020, 7:41:42 PM GMT+1, Christian Grün <christian.gruen at gmail.com> wrote:
Dear BR dudzikp,
You can place your actual test your assertion in a second function with the %unit:after annotation. Another solution is to perform your update in a %unit:before function and test the result in the main function. See [1] for an example.
Cheers,
CG
[1] https://docs.basex.org/wiki/Unit_Module#unit:before
Quoted text · dudzikp at yahoo.com · 23 lines
On Tue, Nov 17, 2020 at 1:20 PM dudzikp at yahoo.com <dudzikp at yahoo.com> wrote: > > Dear all, > > I have not found a way to make basex unit module to test updating functions. I have a function site:add-movies which results in several db:add instructions. > I try to achieve something like: > > declare %unit:test %updating function test-site:download-movies() { > let $result := > site:add-movies( > $test-site:site-db, > test-site:fake-fetch-file#1, > 7 > ) > > return unit:assert-equals(1, 1) (: here I am going to check if db contains expected elements :) > }; > > But let command is not valid for updating expression. Basex docs mention something about update:output and update:cache which may be of some use here but no exhaustive example is given for. > > Anyone had similar problem? > > BR
Written for BaseX 9.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery