InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Article: Unit-Testing XML

Posted by Stefan Tilkov on Jun 11, 2007

Sections
Enterprise Architecture,
Process & Practices,
Development,
Architecture & Design
Topics
SOA ,
Delivering Quality ,
Java ,
Agile ,
Unit Testing ,
Software Testing
Tags
TDD ,
XML ,
XMLUnit ,
Testing ,
Validation
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.
  • This article is part of a featured topic series on SOA and also Agile
Is there an equivalent SoapUnit ? by anjan bacchu Posted
Re: Is there an equivalent SoapUnit ? by Steve Loughran Posted
Re: Is there an equivalent SoapUnit ? by Stefan Bodewig Posted
Re: Is there an equivalent SoapUnit ? by Andreas A Posted
Re: Is there an equivalent SoapUnit ? by Priyanka Grover Posted
The listings are a bit cumbersome... by Krzysztof Witukiewicz Posted
Re: The listings are a bit cumbersome... by Lars Huttar Posted
Ignore special characters while comparing xmls by shireesh adla Posted
  1. Back to top

    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

  2. Back to top

    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>

  3. Back to top

    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.

  4. Back to top

    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

  5. Back to top

    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)

  6. Back to top

    Re: Is there an equivalent SoapUnit ?

    by Priyanka Grover

    SoapUI is extremely good.

  7. Back to top

    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?

  8. Back to top

    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

Educational Content

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.

Architecting Visa for Massive Scale and Continuous Innovation

John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.