Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Should().BeEquivalentTo() show different error message between Debug and Release #1854

@souhailelk

Description

@souhailelk

Description

We compile and launch unit test libraries with the release configuration and x64 platform.
After upgrading FluentAssertions from 4.19.2 to 6.5.1 (the latest), we noticed that Should().BeEquivalentTo() gives different error messages while compare classes with properties.
Let's look at the following example:

  • Let ClassWithProperty be a class containing one property IntProperty:
public sealed class ClassWithProperty
{
    public ClassWithProperty(int value)
    {
        IntProperty = value;
    }
    public int IntProperty { get; }
}
  • The unit test CompareClassWithPropertyObjects compare two objects of type ClassWithProperty, with different property values.
[Test]
public void CompareClassWithPropertyObjects()
{
   //Arrange
    var actual = new ClassWithProperty(1);
    var expected = new ClassWithProperty(2);
    
    //Assert
    actual.Should().BeEquivalentTo(expected);
}

Expected behavior:

Expected property actual.IntProperty to be 2, but found 1.

With configuration:
- Use declared types and members
- Compare enums by value
- Compare tuples by their properties
- Compare anonymous types by their properties
- Compare records by their members
- Match member by name (or throw)
- Be strict about the order of items in byte arrays
- Without automatic conversion.

Actual behavior:

Here, it outputs the }}}, instead of the name of the actual object.

Expected property }}}.IntProperty to be 2, but found 1.

With configuration:
- Use declared types and members
- Compare enums by value
- Compare tuples by their properties
- Compare anonymous types by their properties
- Compare records by their members
- Match member by name (or throw)
- Be strict about the order of items in byte arrays
- Without automatic conversion.

Versions

  • .NET : .NET Core 3.1 and .NET 4.7.1
  • NUnit : 3.12.0 (I tried also the the version 3.13.1, It gives the same results).
  • FluentAssertions : 6.5.1
  • Configuration : Release
  • Platform : x64

Note that it works totally fine in Debug configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions