The Spirit of Schematron in TDD

by Eric Larson

Test Driven Development is a relatively popular methodology nowadays and I think XML tools can play crucial aspect in better testing. Testing frameworks are more than capable of using and testing XML based applications, but just in case you have ever had trouble, here are a few tips.


2008-04-15 16:33:34
Good read.

I can attest to the utility in both Schematron and TDD. One of the problems I've run into with TDD is the issue of "how many unit tests is enough"; by using an approach that favours quantity over quality (lots of lttle assertions being more beneficial than a larger unit test, especially when you build on shifting sands), Schematron allows you to start out with a core set of assertions, and build on them.

>>> This is especially true when you consider tests, which often times are forced to be suboptimal in favor of atomicity, do not need to be fast.


Andrew Welch
2008-04-16 02:10:10

I wrote a small app a while back to allow testing through XSLT (and XPath and XQuery, XML Schema etc)

It was useful at the time to allow XPath 2.0 in XSD 1.0 with the smallest possible change to the validation code (you just use the XCheckerSchemaFactory as the SchemaFactory).

You can augment an XSD with XPath 2.0, or you can just use XPath 2.0, or any combination really.

I wrote it because Schematron disappointed me because all that it was, at heart, was an XSLT 1.0 transform. I kept hearing lots about it, but it turned out to be just a spec and couple of transforms, which rightly or wrongly I couldn't quite belive.

Either way, both are likely to be redundant when XSD 1.1 comes along: XSD 1.0 with the annoyances fixed plus assertions.

Eric Larson
2008-04-16 06:39:51
@ piers

My biggest issue with TDD has been the test frameworks lacking decent ways of testing HTTP for RESTful services. I end up writing my own scripts and using existing tools such as the APE (in the case of AtomPub).

@ Andrew Welch

xchecker looks really cool. I tend to stay away from Java, but it looks so slick I'm going to have to dust of my JVM :) Thanks for the link.

Dimitre Novatchev
2008-04-16 10:03:31
I totally agree with this article and plan to play with Schematron in the nearest future.

One remark is that the text "add your own *extension* functions" provided with the link to FXSL is misleading. FXSL consists of functions all written in 100% pure XSLT.

According to the XSLT 2.0 spec

"Definition: An extension function is a function that is available for use within an XPath expression, other than a core function defined in [Functions and Operators], an additional function defined in this XSLT specification, a constructor function named after an atomic type, or a stylesheet function defined using an xsl:function declaration.]."

All FXSL functions are "a stylesheet function defined using an xsl:function declaration" and according to the XSLT 2.0 spec definition are not "extension functions".

Dimitre Novatchev

Eric Larson
2008-04-16 10:57:29
@ Dimitre

Thanks for the clarification. As part of my goal is to point out your excellent library, I would hate to give folks the wrong impression.

I moved the FXSL link and also went ahead and added a link to the 4Suite server XSLT extension functions. While they are not the most obvious help in testing, it makes it clear that assuming you are comfortable adding functions to your XSLT processor (which really is easy) adding extra semi-custom functionality for the purposes of tests or otherwise can make XSLT that much better a tool.

Also, thanks for creating such a great library. I'm usually using Python for my XSLT work, but since you mentioned FXSL is implemented in XSLT, I will be taking a look at adding it to my XSLTemplates library.

2008-04-17 00:01:28
Maybe XQuery is a good alternative for XSLT !
With XQuery you can use XPath functions.
In fact in our project we have made a QUnit module (just like JUnit) to test our XML/Query based application

declare function ut:testAtomEntry(entry as atom:entry) {
return if (empty(entry/Title)) then "No title" else ()

Eric Larson
2008-04-17 00:22:52
@ Roger

That looks pretty slick! I hope you will consider releasing it at some point as well. I've stuck to XSLT 1.0 simply because of its availability, but I think you've gotten me interested in a close look at Saxon and all it offers.