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

Better format error in case of two arrays/lists not equals #3593

Open
rmannibucau opened this issue Dec 7, 2023 · 1 comment
Open

Better format error in case of two arrays/lists not equals #3593

rmannibucau opened this issue Dec 7, 2023 · 1 comment

Comments

@rmannibucau
Copy link
Contributor

Assertions.assertEqual formats an error when an assertion is false, this is great but in case of lists it is not very readable (and the diff when you click the error in idea is worse).
What could help is that if the instances are collections or arrays to format one item per line, would make it easier to read IMHO.

@shahryarkiani
Copy link

shahryarkiani commented May 30, 2024

I'm interested in working on this, since a vertical format can be quite useful when comparing lists, especially when the elements are of varying lengths. Although, it's probably not a good idea to modify the existing style of error output.
For reference, the existing output looks like this:

expected: <[short, a longer string, even longer string that is annoying]> but was: <[i am a small, i am not so small, tiny]>
Expected :[short, a longer string, even longer string that is annoying]
Actual   :[i am a small, i am not so small, tiny]

I think a good solution would be to expose some static factory methods that return a Supplier<String> that formats the output in a desired format. So a user could do something like:
assertEquals(CollectionA, CollectionB, OutputFormat.ofVertical(CollectionA, CollectionB));
This wouldn't affect any existing user tests/code and would also be flexible to adding new formats. I think it's also not that easy for users to implement the functionality on their own, since getting the spacing right can be tough. A quick Supplier<String> I wrote up looks like this:

expected   |   actual
short | i am a small
a longer string | i am not so small
even longer string that is annoying | tiny

But if this seems like a good idea, I could write it so that we get something like this:

expected                            | actual
short                               | i am a small
a longer string                     | i am not so small
even longer string that is annoying | tiny

(Would also need to handle stuff like unequal collection sizes, maybe including indexes, etc.)
This output would appear above the existing default output, so it does duplicate some information.

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

No branches or pull requests

3 participants