如何使用 ShouldBe 测试 int 相等性

How to test int equality with ShouldBe

我正在 运行 使用 ShouldBe 进行 c# 测试,我有以下代码:

int x = 3;
int y = 3;
x.ShouldBeSameAs(y);

问题是它抛出异常:

An exception of type 'Shouldly.ShouldAssertException' occurred in Shouldly.dll but was not handled in user code

附加信息:x

should be same as

3

but was

3

如何使用 ShouldBe 测试整数的相等性?

只需使用ShouldBe:

x.ShouldBe(y);

根据文档ShouldBeSameAs 使用引用相等。

使用ShouldBe.

参见文档 here