【发布时间】:2018-11-15 16:38:22
【问题描述】:
我的一个包含Assert.Equal(2, list.Count); 的测试在持续集成服务器 Appveyor 上失败,但我无法在本地机器上重现该故障。
我希望从错误信息中得到更多信息,但不知道该怎么做。
xUnit.net 的作者坚持他们不应该允许用户指定自定义错误消息,请参阅https://github.com/xunit/xunit/issues/350。这就是为什么没有 API 允许我编写例如。 Assert.Equal(2, list.Count, "The content of the list is " + ...);
我还研究了 Fluent Assertions。如果我写list.Should().HaveCount(3, "the content of the list is " + ...);,则输出为
预计集合包含 3 个项目,因为列表的内容是
...,但找到了 2 个。
“因为”从句在英语语法中没有意义。因为参数似乎用于描述预期行为,而不是实际行为。
考虑到 xUnit.net 和 Fluent Assertions 都阻止我们提供有关失败的额外信息,当测试失败时输出额外信息是调试远程错误的好方法吗?
输出附加信息的最佳方式是什么?
【问题讨论】:
-
如果您在测试中只断言一件事 - 测试名称可以更具描述性:
Should merge two wildcards。
标签: unit-testing continuous-integration xunit fluent-assertions