How to use Visual Studio unit test to compare two XML files

c#, mstest, unit-testing, visual-studio, visual-studio-2012

Solution

You could try XNode.DeepEquals. Note that for Microsoft's LINQ to XML implementation the element `<foo></foo>` is not the same as `<foo/>`.

If you don't mind 3rd party libraries, you have Saxon and Altova XML Tools.

Also, could be relevant: Xml Comparison in C#.

Problem

I need to write a unit test to confirm that when I modify an XML file I get a specific result. I could simply compare the input and output as strings, but I don't want to get failures if little things like white space between elements are different. Is there a simple way to compare entire XML files in Visual Studio unit tests? (I'm using 2012 if that matters).

Original source

Related problems