question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dennisdoomencommented, Oct 23, 2020

Sure, but it’ll have to be done on all numeric assertions.

0reactions
dennisdoomencommented, Mar 19, 2022

Since you’ll be using a separate branch, you’ll have to create a new PR anyway.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found