中的xUnit github上,我发现这一点:Add Assert.Equal(expected, actual, message) overload #350(因此开发人员要求一个不存在的超载见下文)
报价从答案:
我们是一个信守自我记录的代码;包括你的断言。
(这样的xUnit队拒绝它)
OK,我知道了。我也相信自我记录的代码。我仍然无法找出 这种使用情况:
样品
// Arrange
// Create some external soap service client and its wrapper classes
// Act
// client.SomeMethod();
// Assert
// Sorry, soap service's interface, behaviour and design is *given*
// So I have to check if there is no Error, and
// conveniently if there is, then I would like to see it in the assertion message
Assert.Equal(0, client.ErrorMessage.Length); // Means no error
// I would like to have the same result what would be the following *N*U*n*i*t* assert:
// Assert.AreEqual(0, client.ErrorMessage.Length, client.ErrorMessage); // Means no error
问题
我如何能实现在这种情况下的xUnit仍然没有这样的描述断言消息超负荷?
我不清楚问题是什么。为什么你不只是使用Assert.AreEqual(0,client.ErrorMessage.Length,client.ErrorMessage);'就像你在评论中指出的那样? – Kritner
XUnit没有这样的过载。这是一个NUnit调用。请看最开始的一句话:开发人员要求这样的重载,而XUnit团队因为引用了“我们是自我记录代码的信徒;它包含了你的断言”而拒绝接受“ –
@ g.pickardou,为什么不使用这些建议在链接处提供。像流利的断言一样,或者创建自己的断言来包装那些留下了消息超载的'Assert.True或Assert.False'。它被进一步提到'你可以提供消息给Assert.True和.False。如果你只是不能没有信息而生活(并拒绝使用不同的断言),你总是可以回到: Assert.True(number == 2,“This is my message”); ' – Nkosi