我目前正在嘗試學習如何使用單元測試,並創建了3個動物對象的實際列表以及3個動物對象的預期列表。問題是我如何斷言檢查列表是否相等?我試過CollectionAssert.AreEqual和Assert.AreEqual,但無濟於事。任何幫助,將不勝感激。斷言比較兩個對象列表C#
的測試方法:
[TestMethod]
public void createAnimalsTest2()
{
animalHandler animalHandler = new animalHandler();
// arrange
List<Animal> expected = new List<Animal>();
Animal dog = new Dog("",0);
Animal cat = new Cat("",0);
Animal mouse = new Mouse("",0);
expected.Add(dog);
expected.Add(cat);
expected.Add(mouse);
//actual
List<Animal> actual = animalHandler.createAnimals("","","",0,0,0);
//assert
//this is the line that does not evaluate as true
Assert.Equals(expected ,actual);
}
看一看這個問題的答案S.O.的信息:[http://stackoverflow.com/questions/5194966/mstest-collectionassert-areequivalent-failed-the-expected-collection-contains][1] [1]:HTTP://計算器。 com/questions/5194966/mstest-collectionassert-areequivalent-failed-the-expected-collection-contains – Andrew
這工作,但我不能讓你的評論的答案,謝謝你的幫助,我試圖尋找答案,但無法找到它。 – JamesZeinzu