断言字符串数组不相等但似乎是

时间:2013-03-04 20:30:08

标签: c# unit-testing

我有两个字符串数组,当我检查它们时看起来是一样的。我使用了错误的Assert方法吗?

//Arrange
string[] expected = new[] { "Widget A", "Widget B" };
string[] actual;
//Act
actual = api.GetIncidents(credentials);
//Assert
Assert.AreEqual(expected, actual);

Assert.AreEqual failed. Expected:<System.String[]>. Actual:<System.String[]>.

1 个答案:

答案 0 :(得分:2)

在集合上声明时,您需要CollectionAssert.AreEqual方法和CollectionAssert类:

CollectionAssert.AreEqual(expected, actual);