views:

155

answers:

3

For unit testing XmlDocument, I'm a little bit worried about the way I write test case.

To assert the XmlDocument, I'm creating XmlElements manually. sometime the XmlDocument to test is large, so I need to write a lot of code to build an expected xmldocument. the workload is huge.

Is there any better implement on XmlDocument unit testing?

+1  A: 

XMLUnit does that for you, and usually it's as simple as (in javish, c# should be similar):

XMLUnit.compareXML( expectedXML, codeReturnsXML );
Steen
A: 

It can be very challenging sometimes to test XML. Steen already mention XMLUnit. I've never actually worked with XMLUnit but at some point MbUnit team was planing to add similar functionality.

It looks that at this point MbUnit / Gallio team hasn't implemented it yet. However, part of MbUnit framework is Assert.XmlDeserialize and Assert.XmlSerialize methods.

You can use it like this:

Assert.AreEqual(Assert.XmlSerialize(xmlA), Assert.XmlSerialize(xmlB))

I would also recommend for you to read Unit-Testing XML article by Stefan Bodewig.

Vadim
thanks for the link to the article...
djangofan
+1  A: 

Why not create an XML schema and validate it against that?

David Kiff