What is the difference between Assert.AreEqual and Assert.Equals C #?
|
1 answer
Assert is a normal class that, like all .NET classes, inherits from System.Object . Assert.Equals is simply an inheritable method of Object.Equals .
Asser.AreEquals is a method of the Assert class that throws an AssertFailedException if the two objects are not equal. This is a regular way to check the statement about the equality of two objects.
In the TestFramework version 14.0.0.X, Assert.Equals Assert.Equals blocked and throws an exception to avoid confusion and not mislead anyone. Inside something is written:
/// Static equals overloads are used for comparing instances of two types for reference /// equality. This method should <b>not</b> be used for comparison of two instances for /// equality. This object will <b>always</b> throw with Assert.Fail. Please use /// Assert.AreEqual and associated overloads in your unit tests. public new static bool Equals(object objA, object objB) { Asser.Fail("Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead."); } |