Unit Testing in Visual Studio: what to implement in my class to be able to use Assert.AreEqual?

189 views Asked by At

I'm adding unit testing to my (Visual Basic) project. I'm using the testing tools in Visual Studio (2010 Premium). In a couple of test I would like to make sure that my class is equal to the expected value of the class with Assert.AreEqual. But this doesn't work out of the box.

What is best to do, override the Equals Method implement the IEqualityComparer Interface, or ...?

1

There are 1 answers

1
Robert Slaney On

Assert is a static class, you won't be able to extend the object, or add an extension.

You have 3 choices

  1. Add another Assert static equalivalent class to your project and implement AreEqual taking in IEqualityComparer,

  2. Override the Equals method ( GetHashCode, == and != operators as well )

  3. Use Assert.IsTrue and evaluate using an implementation of IEqualityComparer

Cheers...