我正在编写一个准备好代码的单元测试,并且我收到一个意外的AssertFailedException,试图运行其中一个测试。下面是他:在单元测试中比较两个数组抛出一个AssertFailedException
[TestMethod]
public void TestPositionGetter()
{
testPlayer.Position = new int[] { 1, 3 };
int[] expectedPosition = testPlayer.Position;
Assert.AreEqual(expectedPosition, testPlayer.Position);
}
,这里是在我试图测试Player类的位置属性:
public int[] Position
{
get
{
return new int[] { this.PositionX, this.PositionY };
}
set
{
this.PositionX = value[0];
this.PositionY = value[1];
}
}
调试试验,在局部变量窗口player.Position和expectedPosition是看起来相似,但测试仍然失败。恐怕问题来自于参考。
你可以发布你的错误吗? – Neel
既然已经有了一个很好的答案,我想建议抓住FluentAssertions,因为它有很多非常好的方法来处理IEnumerable对象和其他对象。 – TyCobb
@Anri的口气是正确的,测试通过了。 –