BT

Article: Unit-Testing XML

by Stefan Tilkov on Jun 11, 2007 |
There are many occasions where software creates XML output:  XML documents are used for data interchange between different applications, web application create (X)HTML output or respond to AJAX requests with XML, and this has to be tested as much as anything else.

The major problem with testing operations that produce XML results is to decide whether the result is correct or not, since a simple textual comparison is not enough.

In this exclusive InfoQ article, XMLUnit and Ant contributor Stefan Bodewig explains how to write tests in the presence of XML, showing detailed example scenarios and how to approach them with the help of the XMLUnit Java framework.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Is there an equivalent SoapUnit ? by anjan bacchu

Hi There/Stefan,

Seems to be an useful tool. I've used my home grown xml utilities for command line validation of xml files.

command line usage : I recently came across validate-xml.jar from woodstox "xml Processor" project. This seems to be a decent tool that points out where in an xml file a warning/error lies -- sort of like a compiler output.

It would be nice to have a good WebServices/SOAP Unit Testing tool for the java world. Is there one ? I will be working on a project where I will be developing(exposing) some web services as well as consuming some. It will be nice to have a tool that will test my webservices before the actual client interop tests. What will be nice is to have

a) a command-line client to test some basic webservices functionality like validity, list operations, etc

b) something like XMLUnit which helps in junit/TestNG unit tests.

What do people in the .NET world do ?

Thanks

BR,
~A

Re: Is there an equivalent SoapUnit ? by Steve Loughran

Anjan,
0. Ant has <schemavalidate> to check XSD files; Jing has a relax NG validation task.

1. You can use XMLUnit under TestNG as well as JUnit.

2. SOAP testing? Why would we need to test SOAP? I dont think its really time to improve the testing/debug facilities in SOAP land, because after so many years, you still end up using a TCP trace tool to work out why your messages arent being understood by the far end. Better to start working on the tools we need to make testing RESTy systems easier.

Sorry :)

-Steve

Steve Loughran,
Ant development team,
Author of Ant in Action
</schemavalidate>

Re: Is there an equivalent SoapUnit ? by Stefan Bodewig

as for SOAP specific testing tools, I'm not aware of any.

People in the .NET world use NUnit or MBUnit (very few may use Team Test) - together with XMLUnit for .NET, I hope.

Re: Is there an equivalent SoapUnit ? by Andreas A

soapUI worked pretty good for testing our webservices. Tests can be extended with groovy scripts for automatic input/output transitions between test steps

The listings are a bit cumbersome... by Krzysztof Witukiewicz

...because xml tags are interpreted by the browser :/ If anybody has better 'viewing experience', then please tell me what app do you use (I tried Firefox 2.0, IE6 and Opera 9.02)

Re: Is there an equivalent SoapUnit ? by Priyanka Grover

SoapUI is extremely good.

Re: The listings are a bit cumbersome... by Lars Huttar

I have the same question. I can get to the XML by using "View Source", but as you say it's cumbersome. Firefox 5.0 is not doing any better. Can't blame the browser... InfoQ is outputting the XML unescaped, as if it were part of the HTML. :-S

Could an editor please format the XML code properly?

Ignore special characters while comparing xmls by shireesh adla

Hi,

Not sure if this thread is still active.

iam using Xmlunit to compare xml strings,

Diff diff = new Diff(actualXML, expectedXML);

the comparison fails for similar xml's if they contain special characters in them (eg: both the xml's have "abc-xyz").

Is there any way to ignore special characters while comapring?.

Thanks in advance

Shireesh

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

8 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT