Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear error message for assertSame() #561

Open
dimo414 opened this issue Oct 29, 2014 · 2 comments
Open

Unclear error message for assertSame() #561

dimo414 opened this issue Oct 29, 2014 · 2 comments

Comments

@dimo414
Copy link
Contributor

dimo414 commented Oct 29, 2014

The error message from assertSame() does not make it clear the failure was that the objects aren't identical. Consider assertSame("foo", new String("foo")) - this fails with java.lang.AssertionError: expected [foo] but found [foo]. Granted, the stack trace indicates the error came from assertSame(), but a quick glance at the error text is confusing - didn't it get what it expected?

I'd suggest adding an assertEquals() call inside assertSame() after the equality check, and if that passes (meaning they're equal but not identical) failing with a different message, like expected [foo] but found equivalent but not same [foo].

Less important, but the assertNotSame() error message contains both expected and actual, which are known at that time to be the same object. It seems somewhat unhelpful to include the same object twice in the error.

@FibreFoX
Copy link

Its true that the message is confusing, but i would not suggest to add assertEquals()-calls, it may create unwanted performance-loss (in case the equals-methods are performance-heavy).
Another thing is, when calling assertSame() i dont want to check if the both subjects are equal.

:) but thats just my view of this point

@dimo414
Copy link
Contributor Author

dimo414 commented Oct 30, 2014

I was only suggesting doing an equals() check after the == check has failed, which I don't think would impact performance very much. My thinking is to have a different error message for unequal objects and non-identical objects. When assertSame() fails it would be helpful to know if it's because the objects are outright unequal, or simply not the same object, and the former check and error message is provided out of the box by assertEquals().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants