I am working on Unit Testing for my current project and came across something odd. The .Net UnitTesting library has both Assert.Equals and Assert.AreEqual. The remarks for Assert.Equals say to use Assert.AreEqual to compare two objects, but gives no reason as to why to do so over Assert.Equals. Can somebody explain when you should use Assert.Equals in unit testing, if ever and the difference between Assert.Equals and Assert.AreEqual?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Assert.Equals
is just the Equals
method inherited from object
. It has nothing to do with unit testing, and in fact, has no use.
To be more precise, Assert.Equals
is exactly the same as Object.Equals
. Object.Equals
has a use.
However, if you're using Assert.Equals
, then you're probably confusing it with Assert.AreEqual
, and you want to stop using it.