值在索引 1 处不同 - 对于相等的嵌套数组

Values differ at index 1 - for equal nested arrays

为什么不相等? CollectionAssert 也一样。

        var a = new[] { new[] { 1, 2 }, new[] { 3, 4 } };
        var b = new[] { new[] { 1, 2 }, new[] { 3, 4 } };
        // if you comment these two lines the test passes
        a[0] = a[1];
        b[0] = b[1];
        Assert.That(a, Is.EqualTo(b));

给出:

Expected and actual are both <System.Int32[2][]>
Values differ at index [1]
  Expected and actual are both <System.Int32[2]>

我在 VS .NET 4.5 项目中使用来自 ReSharper 测试 运行ner 的 nunit 2.6.4.14350 和 运行。

对于独立的 NUnit 测试 运行ner (2.6.4) 也是可重现的。

尽管 ab 属于 Int32[2][] 类型,但这并不意味着它们相等 Equals returns 如果 references 你的数组是相同的,但它们不是。您想要的是使用 a.SequenceEquals(b) 检查它们的内容是否相同。

我报告了这个错误,但它已关闭,因为无法修复:https://github.com/nunit/nunit/issues/1209

因此您可以使用 NUnit 3.x 或接受它在 NUnit 2 中被破坏的事实。6.x。