Is there an XML asserts for NUnit?
Asked Answered
R

3

7

Does NUnit support (perhaps by using a third party libraries) a smart comparison for XML data.

Let's say we need to compare two xml files - the simplest way would be to compare xml content using the no-case sensitive string comparison, but that would only work in a trivial cases.

Is there any library around which could simplify xml comparison - e.g. some kind of XmlAssert?

The functionality I am after - "having a two xml files, compare these nodes (because they are important) and ignore the rest".

Similar questions

Razzia answered 24/8, 2010 at 0:11 Comment(0)
H
2

There is work on porting XMLUnit to .Net. I've only used the Java version, and don't know how complete the port is. It may not be ready for prime-time...

Hitlerism answered 24/8, 2010 at 0:26 Comment(2)
Thanks, going give it a try. Last release is dated back to Apr-2009, is it alive project?Razzia
Last commit is pretty recent though - that's a good sign. Thanks.Razzia
Y
2

I was looking for the same kind of tool for .NET and found this: Jolt.NET. Going to try it myself.

Yocum answered 30/5, 2011 at 11:16 Comment(0)
P
1

I haven't used it myself at this point, but fluentassertions.com has a library addon for NUnit and other testing frameworks that allows for this type of assertion. Might be useful to someone.

xDocument.Should()
.HaveElement("child")
.Which.Should()
.BeOfType<XElement>()
.And.HaveAttribute("attr", "1");
Pinto answered 10/8, 2015 at 20:14 Comment(1)
I've now tried fluent assertions myself, and it does perform the exact test the original poster requested very nicely, even if my answer wasn't spot on.Pinto

© 2022 - 2024 — McMap. All rights reserved.