Hi Christian
thank you for the response. The solution is good (far better than code generating .bat files ..).
I slightly modified the solution in order to run the same testsuites with different testdata in one script:
declare function test:runtests() { for-each( map:keys($test:dbset), function($k) { test:runtest($test:dbset($k)) } ) };
declare function test:runtest($databases) { let $testdata := $databases/@data let $name := $databases/@name let $dummy := trace(concat('runtest for testdata : ‘,$name)) let $args := ('-cp','C:\Arbeit\Tools\BaseX932\basex\BaseX.jar','org.basex.BaseX','-b',concat('{mytests}data=',$testdata),'-o',concat('C:\Arbeit\Tasks\UnitTests\TestResult',$name,'.xml'),'-t','C:\Arbeit\Tasks\UnitTests\TestModules')
return ( try {proc:system('java',$args)} catch * { } ) };
let $result := test:runtests()
return()
Using the try / catch block is important here else the script stops when the first test failure occurs.
Markus
Am 20.08.2020 um 09:10 schrieb Christian Grün christian.gruen@gmail.com:
Hi Markus,
Ist es möglich, ein Unit Test Module (https://docs.basex.org/wiki/Unit_Module#Query) über ein XQuery Script zu starten und die Testausgabe in ein File umzuleiten?
As you’ve already noted, unit tests must always be started outside an XQuery expression. The reason is that sequentially executed unit tests may have come with all kinds of side effects which go beyond the scope of a single query.
The following solution doesn’t necessarily distinguish itself through elegance, but you could launch a second BaseX instance with the Process Module [1] and convert the string output to an XML document via fn:parse-xml:
let $args := ('-cp', '/path/to/basex.jar', 'org.basex.BaseX', '-t', '/path/to/tests') let $result := proc:system('java', $args) return parse-xml($result)
This way, your tests will be run in an independent BaseX context. If you invoke the function from the directory in which your BaseX instance and the tests reside, you can omit the absolute paths (/path/to/).
Hoppe this helps, Christian