[xquery-talk] XQuery-based Java Unit tests?
Hans-Juergen Rennau
hrennau at yahoo.de
Tue Mar 8 08:20:54 PST 2011
Hello People,
imagine a Java based system producing XML documents. How to perform unit
testing?
I think the conventional approach of comparing single object fields (or for that
matter, items) with expected values is not sufficient when dealing with complex
documents. It is a problem akin to validation, isn't it? But validating against
the fixed domain schemas is also not enough, as it is usually very specific,
case-dependent contents that must be checked.
So I consider working with XQuery expressions whose Effective Boolean Values are
checked. I imagine that one can easily build a little extension of the testing
framework which encapsulates the XQuery processor and reduces the coding effort
to the habitual level. So we might be able to write something like
assertEBV(doc, namespaceContext, new String[] {
"23 eq count(//item)",
"empty(//item[@quantity ge 10 and not(@discount)])",
...,
});
where "doc" might be, for example, a DOM node, an XML text string, an input
stream, a reader or even a JAXB object which is then marshalled behind the
scenes into XML.
Then one might also think about creating a library of reused XQuery expressions,
so that instead of literal expressions also name references are supported,
allowing for parameters to be passed on as external variables to the XQuery
expression, like so:
assertEBV(doc, namespaceContext, new String[] {
"23 eq count(//item)",
"empty(//item[@quantity ge 10 and not(@discount)])",
"%basicAddressValidator",
"%discountChecker(foo=bar)"
});
My questions:
a) Are there already tools available which support a similar approach?
b) Do you have suggestions how to refine the basic idea?
c) Or are there better alternatives - would you, for example, recommend to use
adhoc schemas instead of a raw list of XQuery expressions, and if so, which
schema language?
Any answers, thoughts or comments appreciated!
With kind regards,
-- Hans-Juergen
More information about the talk
mailing list