Most of my consulting work revolves around XML in some way or another. Much of the code that I write isn't Java/C#/C++/Python, it's XSLT stylesheets. So a lot of the stuff I need to write tests for is XML based.
Now, when I am writing tests for Java, I do what most Java developers do, and use JUnit, which provides a framework for running tests on Java classes (for C#, NUnit provides similar functionality). JUnit will run my tests for me, and display the results graphically, so that I can see how many of my tests passed/failed, and which ones failed. This is a great way to manage your regression testing of existing code, or unit testing of new code.
If I use Ant or Maven to for my Java builds (you can use NAnt for C#), I can get either to run my JUnit tests and produce a report of the results. It's important not to underrate just how important it is to have good reporting tools.
A few years back, when XML databases were coming on to the market, I spent more than a bit of time discussing the pros and cons of them with database administrators. In the XML world, we were excited that XML databases would perform better than relational databases for data that was more tree-like than tabular. However, we rarely got to the subject of performance. The first question was usually something like "so tell me about the reporting tools for this new-fangled XML database of yours". I never got past that argument. Replacing a database might take some effort, but having to replace your reporting tools as well can make the effort 5 times greater. Reporting tools are not something you want to write, but they are something you won't want to live without, particularly if you work on large projects.
Where does all this fit in with XML/XSLT testing? Well, the thing that I want for my XML testing is reporting. I want to be able to run tests, e.g. run some XML through an XSLT stylesheet and compare the output to an expected result. Once those tests are run, I want a report of how many of the tests were successful, which ones were not successful, and why those failing tests were not successful. To do that, I need some kind of framework, like Ant/Maven/Junit (or NAnt/NUnit) give you.
The conclusion that I've recently come to is that the framework I have to use is Ant/Maven/JUnit or NAnt/NUnit, just because there isn't a good alternative around that provides the test result reporting that I'm after. This means that I need to run my XSLT transformations from within Java or C#, and have suitable JUnit/NUnit tests to check the results. It's more code that XML/XSLT developers often want to buy into, but it's a lot less code that writing your own reporting engine in XSLT ...
So I am going to be playing around with how to get this to work best, and seeing what is out there to help me. Right now I have my eye on <XMLUnit/> and Schema Unit Test (SUT) as the two JUnit-for-XML utilities that can help me. I have just signed up with SUT as a developer. They have a JUnit test suite class that can turn a single XML file into a suite of XML examples to test a W3C XML Schema, which is the kind of thing I need for regression testing on Schemas. At the moment, they usually run the JUnit GUI directly, so I will be checking that it runs within Ant and Maven, and tweaking it as required to get it to work. So, expect to hear some more from me about this over the next weeks.
Recent Comments