-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
assertEquals with a diff #3192
Comments
Am I okay to have a crack at this, assuming no one else has picked it up? |
Hey, can I also work on this issue? |
@igmtz please have a go at it |
@igmtz Before this can be started we need to agree an an approach. What did you have in mind? 🙂 |
If you would like us to be able to process this issue, please provide the requested information. If the information is not provided within the next 3 weeks, we will be unable to proceed and this issue will be closed. |
@marcphilipp How about wrapping the empty strings in quotation marks and then displaying the two results? |
If you would like us to be able to process this issue, please provide the requested information. If the information is not provided within the next 3 weeks, we will be unable to proceed and this issue will be closed. |
Hi @marcphilipp, do you think the approach I wrote above would be suitable? Wrapping the strings in quotes - I'm worried about starting the work if it's not the best idea |
@astocker-scottlogic they are not empty strings: they're strings that differ by whitespace only. The method would also be useful when glyphs have a similar appearance but are in fact different, i.e. different code points. I've been in a situation where a colleague thought they were looking at the same string. But on my machine, using a different font, the difference was evident. |
If you would like us to be able to process this issue, please provide the requested information. If the information is not provided within the next 3 weeks, we will be unable to proceed and this issue will be closed. |
Some research: JUnit 4 highlights the differences between two strings with square brackets (see
Spock does this:
JUnit Jupiter currently does this:
We could extend the above message in case we're comparing Strings to show:
That would replace all control characters with their symbol ( @delanym WDYT? |
Looks good! Would the diff come in color? In which case it could be a single line (red square brackets green curly)
Git adds plus/minus
|
I don't think we can do color in the exception message. We could maybe do this in the ConsoleLauncher. There's a similar issue to output a diff there: #3139. |
If you would like us to be able to process this issue, please provide the requested information. If the information is not provided within the next 3 weeks, we will be unable to proceed and this issue will be closed. |
Closing due to lack of requested feedback. If you would like to proceed with your contribution, please provide the requested information and we will re-open this issue. |
When I compare two strings
Assertions.assertEquals(expected, fb.toString());
there's no indication from the error what the difference is if its only whitespace.
So I need to compare the byte arrays instead.
Assertions.assertArrayEquals(expected.getBytes(), fb.toString().getBytes());
If there's a failure I'd like to see the string version (to make sure its roughly the correct string) AND the byte values, but I don't want to waste time comparing both of them to satisfy the test condition.
I guess there are many way to solve this. Maybe its possible to compare the values like assertEquals, and if the test fails, output as usual, but append a diff. "assertNoDiff", "assertEqualsDiff" etc.
The text was updated successfully, but these errors were encountered: