-
Notifications
You must be signed in to change notification settings - Fork 88
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
Better error messages when things are not equal, but the result of toString()
is the same.
#449
Comments
The types can also be the same but have failing equality and matching string representation, so you still need something which highlights this fact. Also, bonus points for:
Truth has all these and it's a great thing to copy. |
Perhaps the best solution would be to just explicitly call out that the two objects are different but have the same class Example {
override fun toString() = "hello"
}
assertThat(Example()).isEqualTo(Example())
// AssertionFailedError: expected (type: `Example`) and actual (type: `Example`) are not equal but have the same string representation: "hello" I'm not sure of the best way to refer to each object there. |
Another case where calling out the behavior is important is when |
Another real world example: JDK 20 (well, the CLDR update in it) changed formatting to use a narrow non-break space from a regular space. Very hard to catch until IntelliJ saved me https://jakewharton.com/@jw/111403629212976596 |
if the types are different, add them to the error message, otherwise just print out that they don't compare equal Fixes #449
if the types are different, add them to the error message, otherwise just print out that they don't compare equal Fixes #449
if the types are different, add them to the error message, otherwise just print out that they don't compare equal Fixes #449
if the types are different, add them to the error message, otherwise just print out that they don't compare equal Fixes #449
if the types are different, add them to the error message, otherwise just print out that they don't compare equal Fixes #449
The original issue should be fixed, @JakeWharton feel free to file new issues for any of the other improvements you suggested |
Consider:
This correctly fails, but the error message can be a bit confusing.
as of
0.25
, the error message is:A couple of thoughts.
CharSequence
not justString
. so thatAnnotatedString
would print as"asdf"
(with quotes)toString()
result is the same, but they are not equal?The text was updated successfully, but these errors were encountered: