1

I am using Assert.Equal(expected,actual) in my unit testing.Eventhough the lists and the order are same it is failing. How to resolve this?

3 Answers3

2

You can use DeepEqual NuGet package and then in the code:

actual.ShouldDeepEqual(expected);

Another option would be to use FluentAssertions NuGet package and then in the code:

actual.Should().BeEquivalentTo(expected);
Misha Zaslavsky
  • 8,414
  • 11
  • 70
  • 116
  • I tried the above working fine for me but not able to compare in order.Is there any way to compare the lists in order ? –  Jul 28 '21 at 07:42
2

I usually just use Assert.True( listOne.SequenceEqual( listTwo ) ).

The downsides are neither list can be null and the results do not indicate a detailed reason for the failure if the test fails.

calicomac
  • 31
  • 5