简体   繁体   English

如何使用ShouldBe测试int相等性

[英]How to test int equality with ShouldBe

I am running c# tests using ShouldBe and I have this code: 我正在使用ShouldBe运行c#测试,并且我有以下代码:

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

Problem is it throws exception: 问题是它引发异常:

An exception of type 'Shouldly.ShouldAssertException' occurred in Shouldly.dll but was not handled in user code “ Shouldly.ShouldAssertException”类型的异常在Shouldly.dll中发生,但未在用户代码中处理

Additional information: x 附加信息:x

should be same as

3 3

but was

3 3

How can I test equality of to integers with ShouldBe? 如何使用ShouldBe测试与整数的相等性?

According to the documentation ShouldBeSameAs uses reference equality. 根据文档, ShouldBeSameAs使用引用相等。

Use ShouldBe . 使用ShouldBe

See documentation here . 请参阅此处的文档。

只需使用ShouldBe

x.ShouldBe(y);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM