10.1 Overview


XMLUnit provides useful support for unit testing of XML content. It is an extension to JUnit and NUnit, rather than a standalone framework.

Development and testing of software that generates XML content are common activities. Writing such tests is difficult with generic unit test frameworks. XML tests often compare expected XML content to actual XML content generated by the software that is being tested . Such tests can be written by doing a string comparison between the expected and actual XML content strings. However, what if the actual XML content contains a return character for readability, or puts XML attributes in opposite order than they appear in the expected XML string? Taken as XML documents, the two XML strings have the same contents, but an exact string comparison will fail.

To further illustrate the problem, the following pieces of XML represent an element named book containing the child elements title and author . Since the child elements are not in the same order, these XML elements have equivalent content, but different syntax:

 <book> <title>Dune</title> <author>Frank Herbert</author> </book> <book> <author>Frank Herbert</author> <title>Dune</title> </book> 

The following representations of an empty XML element named library also have equal content but different syntax:

 <library> </library> <library/> 

It is clearly useful to be able to test that two pieces of XML have the same content despite differences in format.

Other common test cases include verifying XML document validity and extracting the value of a particular node in a document, both of which involve writing a lot of code when building upon the generic xUnit test assert methods .

Thus, it is very useful to add knowledge of XML content, parsing, and validity to a unit test framework. XMLUnit addresses this need with a set of functional and powerful tests for XML content.

XMLUnit is open source software authored by Tim Bacon and Jeff Martin. It is released under a BSD license that freely allows redistribution and use of the source and binary code in both original and modified versions, as long as the original copyright notice is included. See the license file included with XMLUnit for full details.

For more information about XMLUnit, see http://xmlunit. sourceforge .net. The information in this chapter is based on XMLUnit for Java 1.0. The NUnit version, XMLUnit .Net 0.3, is very similar but is at an earlier stage of development.

Unit Test Frameworks
Unit Test Frameworks
ISBN: 0596006896
EAN: 2147483647
Year: 2006
Pages: 146
Authors: Paul Hamill

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net