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.

Some assertions are not including variable names in assertion message

See original GitHub issue

Description

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 DateTimes, Guids, 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:closed
  • Created 3 years ago
  • Comments:29 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
Serg046commented, Oct 29, 2020

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.

1reaction
mdentremontcommented, Jul 19, 2021

Woot! Thanks so much @dennisdoomen & @jnyrup (and of course @Serg046 for doing most of code)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to show the variable name on the exception message ...
How to show the variable name on the exception message when the assertion fails using FluentAssertions?
Read more >
How do I assert that the response contains a variable name
The most commonly used assertion is the Response Assertion, which checks whether a response text/body/code/message/header contains, matches, ...
Read more >
Python's assert: Debug and Test Your Code Like a Pro
In this tutorial, you'll learn how to use Python's assert statement to document, debug, and test code in development.
Read more >
Programming With Assertions
An assertion is a statement in the Java programming language that enables you to test your assumptions about your program. For example, if...
Read more >
Context Variables within Custom Assertions - TechDocs
Context variables are variables that are set or read from assertions at policy execution runtime. Custom assertions can participate in this ...
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