You can use XMLUnit without subclassing

I had almost written off XMLUnit because I assumed it required subclassing XMLTestCase and I already have my own JUnit TestCase sublass that I like to use. However, to my delight I discovered they have refactored out an XMLAssert class full of static assert methods so that you can call them anywhere.

If you've never heard of XMLUnit it's a nice library that lets you compare XML documents for equality or subsets thereof using XPath. Very nice for creating unit tests to verify that the XML your classes are returning is what you expect without worrying about linebreaks, whitespace, and other pesky formatting details if you were trying to do it with String.equals or String.indexOf.

This entry was posted in Java. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *