Edit 2 xUnit 2 eventually completely moved the statements to a separate assembly. NuGet only has compiled and source packages, and the Assert class is partial, so using the original version of the package, Assert becomes very easily extensible (in C #, that is).
Change For completeness: xUnit 2 removes this extension point and recommends using extension methods in the strings of βfreeβ claim libraries.
For completeness, here is a description of the βofficialβ way to extend Assert (which is surprisingly not mentioned at all, despite the fact that Brad Wilson even joined the discussion).
In version 1.5 (according to Brad's blog) xUnit.Extensions has explicit support for this through the Assertions and TestClass . It works as follows:
TestClass has an Assert property, which is of type Assertions , which passes all methods to Xunit.Assert . Since TestClass.Assert is an instance, you can add methods to it using extension methods on Assertions :
public static class AssertionsExtensions { public static void DeepEquals(this Assertions assertions, XNode expected, XNode actual) { assertions.True(XNode.DeepEquals(expected, actual));
Now you need to get your test class from Xunit.Extensions.TestClass (confused, there is also Xunit.TestClass , which is not what you want), and the Assert property will "shade" like Xunit.Assert , unless you explicitly qualify this name .
In your test class, which is derived from TestClass , you can now use
Assert.DeepEquals(expectedXml, actualXml);
The only real difference from the built-in xUnit statement (except that the syntax coloring for Assert is an identifier, not a type) is that when it fails, you just get a TrueException , not a specific DeepEqualsException , which could hypothetically tell you where the comparison failed. But of course, you could build this too.