代码之家  ›  专栏  ›  技术社区  ›  Gqqnbig

测试失败时输出附加信息

  •  0
  • Gqqnbig  · 技术社区  · 8 年前

    Assert.Equal(2, list.Count);

    enter image description here

    https://github.com/xunit/xunit/issues/350 Assert.Equal(2, list.Count, "The content of the list is " + ...);

    list.Should().HaveCount(3, "the content of the list is " + ...);

    预期集合包含3项,因为列表的内容为

    1 回复  |  直到 8 年前
        1
  •  3
  •   Dennis Doomen    8 年前

    using (new AssertionScope(Formatter.ToString(list)) { list.Should().HaveCount(3); }

    collection

    because

    list.Should().HaveCount(3, "because I expected list {0} to contain that many items", list);

    Formatter.String