Skip to content

Improve messages for numeric assertions to show the difference of the comparison #1412

@augustoproiete

Description

@augustoproiete

I'd like to discuss a possible improvement to the error messages on numeric assertions (which I'm happy to take a stab and send a PR once a design is agreed):

Given a test similar to this:

var expectedResult = 832168464;
var actualResult = 832168447;

actualResult.Should().Be(expectedResult);

The error message currently would be:

Expected actualResult to be 832168464, but found 832168447.

This is great, but given we're comparing numbers, it would be more useful if the error message included the difference, instead of the developer having to calculate it separately from the error message. e.g.

Expected actualResult to be 832168464, but found 832168447. Difference: -17

The difference when comparing numeric values is usually a good clue when trying to understand why the test failed, and displaying it as part of the error message makes the experience better.


Is there a desire to have something like that implemented?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions