How to test int equality with ShouldBe

4.4k Views Asked by At

I am running c# tests using ShouldBe and I have this code:

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

Additional information: x

should be same as

3

but was

3

How can I test equality of to integers with ShouldBe?

2

There are 2 best solutions below

0
jProg2015 On BEST ANSWER

According to the documentation ShouldBeSameAs uses reference equality.

Use ShouldBe.

See documentation here.

0
Joey On

Just use ShouldBe:

x.ShouldBe(y);