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.

Assertion failure text includes excessive source code

See original GitHub issue

Description

I’m running a rather long and verbose test; bear with me please. I’ve placed its code—and the response—below for easier reading.

The problem is that when an assertion fails, the remainder of the code starting at the point of the assertion is dumped into the failure output. Given the complexity of the test, this results in a very difficult-to-interpret response.

Is this by design, a bug or merely a misconfiguration on my part?

Reproduction Steps

Expected behavior

Actual behavior

The entirety of the source code starting at the point of assertion failure (in this case line 65 above) is included in the output.

Regression?

This has been occurring for some time (years), but it’s finally pushed me to the edge. Thus I’m raising this issue.

Known Workarounds

No response

Configuration

.NET 7 v6.11.0 VS 2022

Other information

I tried doing something akin to this:

Using oScope As New AssertionScope
  oScope.FormattingOptions.MaxLines = 3

End Using

But it had no effect.

Issue Analytics

  • State:closed
  • Created a month ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
jnyrupcommented, Aug 13, 2023

FYI, I’ve merged a PR that improves the caller identification for VB. I also noticed that if you Should() instead of the shorthand Should, the current version of FA Should work as expected.

2reactions
InteXXcommented, Aug 11, 2023

@dennisdoomen

It parses the C# code that invokes Fluent Assertions so it can…

Ah, gotcha.

Well… here’s what I’ve done as a workaround, based on @jnyrup’s suggestion:

<Fact>
Public Sub SomeTest()
  ' Arrange

  ' Act

  ' Assert
  Using oScope As New AssertionScope("Test")
  End Using
End Sub

I dropped that as a double-click-to-paste template into my VS Toolbox pane and it works just fine. I can live with that if you’ve got better things to do than worry with this whole thing (and I suspect you do).

Here’s my new output:

Expected Test {"Orange", "Apple"} to contain "Mango".

Luv it. I can get back to work now. And I think you should too.

Thanks @jnyrup!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python assert -- improved introspection of failure?
Your function, if the second argument is AssertionError , can introspect to your heart's contents; in particular, through the third argument, ...
Read more >
Add Assert.Equal(expected, actual, message) overload #350
I'd love to see feature parity with MSUnit and NUnit, which both already support overloads for equality with user-specified messages.
Read more >
Understanding assertions – Hacking with Swift+
If you build with unchecked optimizations, the compiler is free to assume that your assertionFailure() code is never called – it should be ......
Read more >
Stop requiring only one assertion per unit test: Multiple ...
A test must have only one assertion. That idea is rarely helpful. Let's examine a realistic code example and subsequently try to understand ......
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 >

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