Here’s my test function (c#, visual studio 2010):
[TestMethod()]
public void TestGetRelevantWeeks()
{
List<sbyte> expected = new List<sbyte>() { 2, 1, 52, 51, 50, 49, 48, 47, 46, 45 };
List<sbyte> actual = new List<sbyte>() { 2, 1, 52, 51, 50, 49, 48, 47, 46, 45 };
Assert.AreEqual<List<sbyte>>(expected, actual);
}
Exception:
Failed TestGetRelevantWeek Assert.AreEqual failed.
Expected:System.Collections.Generic.List 1[System.SByte].
Actual:System.Collections.Generic.List 1[System.SByte].
Does AreEqual only check equality of the reference, not the contents?
But then, the exception message would be confusing. I also couldn’t find a documentation of the default equality comparer for a generic list.
Could you help to clarify why the test fails and what would be solutions for testing the equality of the contents of both lists?
Kind regards
The
Assert.AreEqual()method does a reference equality test as you expected.Assuming you’re using .Net 3.5 or above, you can do this:
Edit: Clarified when this option is available.