当我有一个然后创建一个与实际值相同Dictionary<string, int> actual
的全新时。Dictionary<string, int> expected
调用
Assert.That(actual, Is.EqualTo(expected));
使测试通过。使用
Assert.That(actual, Is.EquivalentTo(expected));
时测试不通过。
EqualTo()
和 和有什么不一样EquivalentTo()
?
编辑:
测试不通过时的异常信息如下:
Zoozle.Tests.Unit.PredictionTests.ReturnsDriversSelectedMoreThanOnceAndTheirPositions:
Expected: equivalent to < [Michael Schumacher, System.Collections.Generic.List`1[System.Int32]] >
But was: < [Michael Schumacher, System.Collections.Generic.List`1[System.Int32]] >
我的代码如下所示:
[Test]
public void ReturnsDriversSelectedMoreThanOnceAndTheirPositions()
{
//arrange
Prediction prediction = new Prediction();
Dictionary<string, List<int>> expected = new Dictionary<string, List<int>>()
{
{ "Michael Schumacher", new List<int> { 1, 2 } }
};
//act
var actual = prediction.CheckForDriversSelectedMoreThanOnce();
//assert
//Assert.That(actual, Is.EqualTo(expected));
Assert.That(actual, Is.EquivalentTo(expected));
}
public Dictionary<string, List<int>> CheckForDriversSelectedMoreThanOnce()
{
Dictionary<string, List<int>> expected = new Dictionary<string, List<int>>();
expected.Add("Michael Schumacher", new List<int> { 1, 2 });
return expected;
}