Tuesday, March 8, 2011

How Scala helps with Orbeon Forms unit tests

For the server component of Orbeon Forms, we started using the Scala language in addition to Java last year.

A killer feature of Scala for Java programmers is that it integrates very smoothly with Java. For example, Scala classes can extend Java classes an vice-versa, and all Java libraries can be used transparently from Scala.

This also goes for the JUnit testing framework that we use for our server-side unit tests, which run every time a build of Orbeon Forms is created (often that's several times a day!). Scala has a few test frameworks, and we picked ScalaTest, which can be used on top of JUnit.

Some unit tests that we need to write need as source a short XForms page, which must run through the XForms processor. Once the XForms document is "live", we need to poke it a little bit (for example by changing the values of some fields), and then test some assertions.

This is one area where Scala turns out to be very elegant, because the XForms page can be embedded directly in the Scala code. Here is an example of this:

With this kind of setup, it's (almost) a pleasure to write unit tests!

No comments:

Post a Comment