Mental Block

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:

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s