No Free Time

April 5, 2008

MSTest still doesn’t assert array equality properly

Filed under: testing — Tags: , — andrewmyhre @ 9:49 pm

I ran into this issue today where asserting equality on two arrays always fails, even if the arrays really are equal:

Assert.Equals(new string[] {”value”}, new string[] {”value”}); // always fails

Evidently for arrays the Assert.Equals() method tests object identity, rather object equality, which is what you would expect. There is an Assert.AreSame() method which should test object identity, shouldn’t it?

I found this post from 2005 which notes the problem - I can’t believe they haven’t fixed it by now!

Blog at WordPress.com.