0

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 ...?

user5158192
  • 1
  • 1
  • 2
  • That's exactly one of the reasons why you should avoid using MSTest. Have a look at a real testing framework such as NUnit, Gallio/MbUnit, or xUnit.Net. – Yann Trevin Feb 17 '11 at 20:48

1 Answers1

0

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...

Robert Slaney
  • 3,712
  • 1
  • 21
  • 25
  • Thank you! The second choice is completely clear to me. With the third you mean that implementing IEqualityComparer doesn't lend itself for using Assert.AreEqual, aren't you? You wouldn't happen to have a link to some more explanation about the first option? – user5158192 Feb 21 '11 at 09:29