[英]Fluent Assertions: Be() vs Equals()
What is the difference between:有什么区别:
subject.Should().Be(expected)
subject.Should().Equals(expected)
I always use Be()
, but I now have a testcase where Be()
gives a different result, then Equals()
.我总是使用Be()
,但我现在有一个测试用例,其中Be()
给出不同的结果,然后是Equals()
。 My testcase involves a struct and comparing it with the default of that struct.我的测试用例涉及一个结构并将其与该结构的默认值进行比较。
MyStruct subject = new MyStruct("value");
Assert.Equal(default, subject); // xUnit Assert => works
Assert.Equal(default(MyStruct), (object)subject); // xUnit Assert => works
subject.Should().Equals(default); // works
subject.Should().Be(default(MyStruct)); // FAILS!
Are Be()
and Equal()
the same and is this a bug in Fluent Assertions? Be()
和Equal()
是否相同,这是 Fluent Assertions 中的错误吗? Or are they asserting different things?还是他们在断言不同的事情?
The Equals
method comes from System.Object
. Equals
方法来自System.Object
。
You actually compare an object of Type ObjectAssertions
with the default value of object( null
).实际上,您将 ObjectAssertions 类型的ObjectAssertions
与对象的默认值( null
)进行比较。
This is not an assertion.这不是一个断言。
The method returns a boolean that is false.该方法返回一个错误的 boolean。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.