You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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().
The error message from
assertSame()
does not make it clear the failure was that the objects aren't identical. ConsiderassertSame("foo", new String("foo"))
- this fails withjava.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 insideassertSame()
after the equality check, and if that passes (meaning they're equal but not identical) failing with a different message, likeexpected [foo] but found equivalent but not same [foo]
.Less important, but the
assertNotSame()
error message contains bothexpected
andactual
, which are known at that time to be the same object. It seems somewhat unhelpful to include the same object twice in the error.The text was updated successfully, but these errors were encountered: