Assertion messages could be confusing
See original GitHub issueHere 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:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top 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 >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
I’m back with very little information, but in this message
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 usingfakeManager.FakeObjectType
.That’s why we’re seeing the difference.
I’m half thinking that we might be better off with
fakeManger.FakeObjectType
all over.The printing via
ToString()
is something I didn’t think of and definitely should do 👍.