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 messages could be confusing

See original GitHub issue

Here is the minimal example (body of some class Test):

public class Something { }

public interface IFoo
{
    void Method(Something x);
}
public interface Bar : IFoo { }

[Fact]
public void Test14()
{
    var fake = A.Fake<Bar>();
    fake.Method(new Something()); 
    // asserting different object
    A.CallTo(()=>fake.Method(new Something())).MustHaveHappened();
}

Prints:

FakeItEasy.ExpectationException : 

  Assertion failed for the following call:
    Test.Test+IFoo.Method(x: TestUtil.Attributes.Test+Something)
  Expected to find it once or more but didn't find it among the calls:
    1: Test.Test+Bar.Method(x: TestUtil.Attributes.Test+Something)

The method name/defining type should be the same in both cases not Test+IFoo.Method and Test+Bar.Method. Now it looks like there is other problem than the non-mathing parameter as it is the only different thing in the calls as printed.

Also <del>it would be helpful if the assert message would be different when no calls to a methods were made and when the parameter assertions does not match, because</del> it is kind of silly to print something like in the example where the actual parameter looks same as the required one.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
blairconradcommented, Dec 3, 2022

I’m back with very little information, but in this message

Assertion failed for the following call:
  FIEQuestions.Test+IFoo.Method(x: Something 2)
Expected to find it once or more but didn't find it among the calls:
  1: FIEQuestions.Test+Bar.Method(x: Something 1)

The line that references “Something 2” makes up the reported type name using method.DeclaringType. The “Something 1” line makes up the reported type name using fakeManager.FakeObjectType.

That’s why we’re seeing the difference.

I’m half thinking that we might be better off with fakeManger.FakeObjectType all over.

0reactions
Bludatorcommented, Dec 1, 2022

The printing via ToString() is something I didn’t think of and definitely should do 👍.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Some CompletableFuture assertion error message are ...
The exception report can be quite confusing because between the test failure and the printing of the test error, the future might complete....
Read more >
Good assertion messages with EmberJS + sinon
Because of the point above, in case you have other types of assertions, it might be confusing to know which message belongs to...
Read more >
Can java's assert statement allow you to specify a message?
Currently an AssertionError gets thrown, can you specify a custom message for it? Can you show an example mechanism for doing this (other...
Read more >
An Exploratory Study on the Usage and Readability ...
The heuristics we find in this study can help code readability models, which currently do not directly support messages within assertion methods ...
Read more >
Assertion messages in tests
From a test readability perspective, assertion messages are code comments. Instead of relying on them, refactor tests to be self-documenting. In ...
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