Fluentassertions: Test output is faulty when asserting a string with curly braces ({}) inside.

Created on 2 Feb 2017  路  4Comments  路  Source: fluentassertions/fluentassertions

Using the following code:

string actualTest = "{}";
actualTest.Should().Be("{{}}"); //should fail

I get this output:

Expected string to be "{{}}" with a length of 4, but "{{}}" has a length of 2.
   bei FluentAssertions.Execution.LateBoundTestFramework.Throw(String聽message) in z:\Builds\work\d21bade4fe20a99b\Shared\Execution\LateBoundTestFramework.cs: line 30.
   bei FluentAssertions.Execution.AssertionScope.FailWith(String聽failureMessage,聽Object[]聽failureArgs) in z:\Builds\work\d21bade4fe20a99b\FluentAssertions.Core\Execution\AssertionScope.cs: line 168.
   bei FluentAssertions.Primitives.StringEqualityValidator.ValidateAgainstLengthDifferences() in z:\Builds\work\d21bade4fe20a99b\FluentAssertions.Core\Primitives\StringEqualityValidator.cs: line 40.
   bei FluentAssertions.Primitives.StringValidator.Validate() in z:\Builds\work\d21bade4fe20a99b\FluentAssertions.Core\Primitives\StringValidator.cs: line 42.
   bei FluentAssertions.Primitives.StringAssertions.Be(String聽expected,聽String聽because,聽Object[]聽reasonArgs) in z:\Builds\work\d21bade4fe20a99b\FluentAssertions.Core\Primitives\StringAssertions.cs: line 40.
...

This test fails, of course but:

Note that the presented strings seem both to have 4 characters in them, but are reported as different. This is true, the test fails correclty, but the output is very misleading.

bug

Most helpful comment

Just FYI, I found that on release 3.2.1, using Visual Studio 2015, in a .NET 4.5.2 Unit test project.

All 4 comments

Looks like聽I've been overzealous with escaping braces ;-).

Thanks for reporting it.

I just tried it with the current master version and the problem seems to have disappeared:

Expected string to be "{{}}" with a length of 4, but "{}" has a length of 2.

Good to know. We are using an older release, but I do not know exactly which one from the top of my head.

Just FYI, I found that on release 3.2.1, using Visual Studio 2015, in a .NET 4.5.2 Unit test project.

Was this page helpful?
0 / 5 - 0 ratings