What is difference between EqualTo() and EquivalentTo() in NUnit?

Viewed 5953

When I have a Dictionary<string, int> actual and then create a completely new Dictionary<string, int> expected with the same values as actual.

  • Calling Assert.That(actual, Is.EqualTo(expected)); makes the test pass.

  • When using Assert.That(actual, Is.EquivalentTo(expected)); the test doesn't pass.

What is the difference between EqualTo() and EquivalentTo()?

Edit:

The message of the exception when the test doesn't pass is as follows:

Zoozle.Tests.Unit.PredictionTests.ReturnsDriversSelectedMoreThanOnceAndTheirPositions:
Expected: equivalent to < [Michael Schumacher, System.Collections.Generic.List`1[System.Int32]] >
But was:  < [Michael Schumacher, System.Collections.Generic.List`1[System.Int32]] >

My code looks like this:

[Test]
public void ReturnsDriversSelectedMoreThanOnceAndTheirPositions()
{
    //arrange
    Prediction prediction = new Prediction();

    Dictionary<string, List<int>> expected = new Dictionary<string, List<int>>()
    {
        { "Michael Schumacher", new List<int> { 1, 2 } }
    };

    //act
    var actual = prediction.CheckForDriversSelectedMoreThanOnce();

    //assert
    //Assert.That(actual, Is.EqualTo(expected));
    Assert.That(actual, Is.EquivalentTo(expected));
}

public Dictionary<string, List<int>> CheckForDriversSelectedMoreThanOnce()
{
    Dictionary<string, List<int>> expected = new Dictionary<string, List<int>>();
    expected.Add("Michael Schumacher", new List<int> { 1, 2 });

    return expected;
}
2 Answers
Related