Improve messages for numeric assertions to show the difference of the comparison
See original GitHub issueI’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?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Just Use FluentAssertions - Tinkerer
In this post I'm going to compare FluentAssertions to the built-in xUnit assertions ... FailWith(String message, Object[] args) at FluentAssertions.Numeric.
Read more >Assertion messages in tests
In this post, we'll talk about whether or not you should use assertion messages in tests.
Read more >c# - Fluent Assertions: Approximately compare a classes ...
Another approach is to explicitly tell to FluentAssertions which properties should be compared, but it's a bit less elegant : double precision = ......
Read more >Tips - Fluent Assertions
The examples below show how you might improve your existing assertions to both get more readable assertions and much more informative failure messages....
Read more >9 Fluent Assertions Tricks to Save Hours of Your Testing ...
Be(otherCustomer); In the above case, the Be method uses the Equals method on the type to perform the comparison. Next, you can perform...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure, but it’ll have to be done on all numeric assertions.
Since you’ll be using a separate branch, you’ll have to create a new PR anyway.