Some assertions are not including variable names in assertion message
See original GitHub issueDescription
When using fluent assertions for things like objects & lists, assertion failures will typically log the names of the variables. This doesn’t appear to happen when comparing DateTime
s, Guid
s, objects, etc.
It is very useful to have the variables names for context, as when the assertion message doesn’t have these it is difficultto figure out which assertion failed when looking at test output for “AssertionScope” blocks (and for non-assertion scope blocks, you can only find the failing assertion via the line numbers in the stack).
Here is what the output looks like for one of the assertions which includes variables names:
var z = "SSSS";
z.Should().Contain("BBB");
> Expected z "SSSS" to contain "bbb".
Complete minimal example reproducing the issue
var x = DateTime.UtcNow;
var y = DateTime.UtcNow.AddSeconds(1);
x.Should().Be(y);
Expected behavior:
Assertion failure should be something like: Expected x to be <2020-07-15 16:51:43.1621939>, but was <2020-07-15 16:51:43.5991913>.
Actual behavior:
Expected date and time to be <2020-07-15 16:51:43.1621939>, but found <2020-07-15 16:51:43.5991913>.
Versions
- FluentAssertions 5.10.2
- .NET framework 4.8
Issue Analytics
- State:
- Created 3 years ago
- Comments:29 (18 by maintainers)
Top GitHub Comments
Since I see your interest, I will create one and put it here. Then we can benchmark it and understand if this is an option for us. Additionally, it will give us a chance to give some more data for other places when needed.
Woot! Thanks so much @dennisdoomen & @jnyrup (and of course @Serg046 for doing most of code)