开发者

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

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜