Today, I seem to be having a mental block while writing some unit tests. I keep writing Assert.AreSame()
instead of Assert.AreEqual()
and then wondering why tests are failing with bizarre message like “Expected 2, Actual 2”
Just in case anyone else has a day like this I’m going to explain the difference (although mainly as a bit of therapy for myself)
The AreSame()
method checks that the expected and the actual reference the exact same “physical” object.
The AreEqual()
method checks that the expected and the actual are equal to one another, even if they are not “physically” the same object.
NOTE: This was rescued from the Google Cache. The original was dated Friday, 21st July, 2006.
Tags: unit test
assert
mental block