Wednesday, May 21, 2008

XQuery and Unit testing - Part III (xqUnit)

A short post this time - I think that

(: a test definition :)
let $test :=
<test>
<method>
let $book:= /bib/book
</method>
<asserts>
<assertTrue name="count nodes">
return count($book) = 4
</assertTrue>
<assertTrue name="find by name">
return $book[1]/title = "TCP/IP Illustrated"
</assertTrue>
<assertTrue name="find by author">
return count($book[author/last = "Stevens"]) = 2
</assertTrue>
<assertTrue name="find by author case sensitivty">
return count($book[author/last = "stevens"]) = 0
</assertTrue>
</asserts>
</test>


looks better from a naming point of view, it gives a better idea of intent and opens up the options for other kinds of asserts.

Once we apply a schema to this model, the xqunit:excute function can be locked down to expecting an assert rather than any node...
{"cc_re__cc_re__cc_by_3_0": ["/div>\n<div class='cap-right'></div>\n</div>\n<div class='fauxborder-left footer-fauxborder-left'>\n<div class='fauxborder-right footer-fauxborder-right'></div>\n<div class='region-inner footer-inner'>\n<div class='foot no-items section' id='footer-1'></div>\n<!-- outside of the include in order to lock Attribution widget -->\n<div class='foot section' id='footer-3' name='Footer'><div class='widget Attribution' data-version='1' id='Attribution1'>\n<div class='widget-content' style='text-align: center;'>\n<a href=\"http://creativecommons.org/licenses/by/3.0/\">CC BY Figment Engine</a><br>. Travel theme. Powered by <a href='https://www.blogger.com' target='_blank'>Blogger</a>.\n</div>\n<div class='clear'></div>\n</div></div>\n</div>\n</div>\n<div class='footer-cap-bottom cap-bottom'>\n<div class='cap-left'></div>\n<div class='cap-right'></div>\n</div>\n</div>\n</footer>\n<!-- content -->\n</div>\n</div>\n<div class='content-cap-bottom cap-bottom'>\n<div class='cap-left'></div>\n<div class='cap-right'></div>\n</div>\n</div>\n</div>\n<script type='text/javascript'>\n    windo"]}