SHARE
TWEET

C# UnitTest - Assert.AreEqual() does not call Equals if the argument is null

a guest Feb 26th, 2012 21 Never
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2.  
  3. class TestClass
  4. {
  5.     public override bool Equals(object obj)
  6.     {
  7.         return true;
  8.     }
  9. }
  10.  
  11. [TestMethod]
  12. public void TestMethod1()
  13. {
  14.     TestClass t = new TestClass ();
  15.     Assert.AreEqual (t, null); // fails
  16.     Assert.IsTrue (t.Equals (null)); // passes
  17. }
RAW Paste Data
Top