Skip to content

Unclear error message for assertSame() #10

Description

@dimo414

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions