Difference between revisions of "EXist-db testing"

(Created page with "first version")
 
Line 1: Line 1:
first version
+
This page will explore how to add (autmated) tests to the XQuery code of art-decor.
 +
 
 +
== Why the eXist-db XQSuite is unsuitable ==
 +
 
 +
eXist offers a standard testing framework for testing XQuery function modules, [http://exist-db.org/exist/apps/doc/xqsuite.xml XQSuite]. It seems however totally unsuitable for anything but simple testing scenarios.
 +
 
 +
XQSuite works by adding annotations to the function declaration, for example:
 +
 
 +
  declare
 +
    %test:arg("a", 3) %test:assertEquals(27)
 +
    %test:arg("a", 4) %test:assertEquals(64)
 +
  function tt:testthis(
 +
    $a as xs:integer
 +
  ) as xs:integer
 +
  {
 +
    $a * $a * $a
 +
  };
 +
 
 +
XQsuite doesn't fit the bill because:
 +
 
 +
* It does '''not''' support passing parameters other than atomic types (strings, integers, etc.). You can't pass elements, attributes or documents as function parameters.
 +
* The same is true for the function's result type. You can't test it when it's not an atomic type.
 +
* You can't add any documentations or annotations to a test or a bunch of tests. This means that when you get an error you have to search the tests where it came from and infer from that what's wrong.
 +
* You can't use other functions, variables, etc. in setting up the test or testing the result. Everything passed in and tested against must be literal.
 +
* When your function is more than trivial (and most are) the list of test annotations will be rather long and clutter the code
 +
* According to the documentation you can do a test setup and tear-down, but I couldn't get that working. Anyway, that will only work for testing a single function. But what if you want to do an extensive time-consuming setup/tear-down (e.g. setting up a reference art-decor-project) once for a whole group of tests?

Revision as of 09:28, 15 October 2018

This page will explore how to add (autmated) tests to the XQuery code of art-decor.

Why the eXist-db XQSuite is unsuitable

eXist offers a standard testing framework for testing XQuery function modules, XQSuite. It seems however totally unsuitable for anything but simple testing scenarios.

XQSuite works by adding annotations to the function declaration, for example:

 declare 
   %test:arg("a", 3) %test:assertEquals(27)
   %test:arg("a", 4) %test:assertEquals(64)
 function tt:testthis(
   $a as xs:integer
 ) as xs:integer
 {
   $a * $a * $a
 };

XQsuite doesn't fit the bill because:

  • It does not support passing parameters other than atomic types (strings, integers, etc.). You can't pass elements, attributes or documents as function parameters.
  • The same is true for the function's result type. You can't test it when it's not an atomic type.
  • You can't add any documentations or annotations to a test or a bunch of tests. This means that when you get an error you have to search the tests where it came from and infer from that what's wrong.
  • You can't use other functions, variables, etc. in setting up the test or testing the result. Everything passed in and tested against must be literal.
  • When your function is more than trivial (and most are) the list of test annotations will be rather long and clutter the code
  • According to the documentation you can do a test setup and tear-down, but I couldn't get that working. Anyway, that will only work for testing a single function. But what if you want to do an extensive time-consuming setup/tear-down (e.g. setting up a reference art-decor-project) once for a whole group of tests?