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

A sort of fix for issue #1127 (take 2) #1300

Conversation

tomwhoiscontrary
Copy link
Contributor

This is substantially the same change as in #1216, ported onto master as discussed. I will repeat the PR blurb for ease of reading ...

In issue #1127, @sf105 noted that when comparing two arrays which differ in length, assertArrayEquals() will only report that they differ in length, which he found insufficient for easy diagnosis. As a fix, he suggested printing the complete actual array contents.

Rather than doing that, this PR changes assertArrayEquals() to do the usual array comparison even when arrays differ in length, producing a failure message which combines the difference in length and the first difference in content. I think this should ease diagnosis, as @sf105 wanted, and it doesn't require making big changes to the code, adding Hamcrest, introducing a new behaviour (JUnit doesn't print complete array contents anywhere else), or blowing people's IDEs up when they compare multi-megabyte byte arrays.

int actualsLength = Array.getLength(actuals);
int expectedsLength = Array.getLength(expecteds);
if (actualsLength != expectedsLength) {
header = header + "array lengths differed, expected.length="
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+=?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do. I always get a bit creeped out by doing += on strings, for some reason!

@marcphilipp
Copy link
Member

This change looks really useful.

@junit-team/junit-committers Please take a look! :-)

@kcooney
Copy link
Member

kcooney commented May 19, 2016

I agree with Marc

@kcooney kcooney closed this in b2d7fce May 29, 2016
@kcooney
Copy link
Member

kcooney commented May 29, 2016

Merged. Thanks!

@tomwhoiscontrary could you please update the release notes at https://github.com/junit-team/junit4/wiki/4.13-Release-Notes ?

@tomwhoiscontrary
Copy link
Contributor Author

@kcooney Thanks. Release note added - let me know if it needs improving.

@kcooney
Copy link
Member

kcooney commented May 30, 2016

@tomwhoiscontrary looks great. Thanks!

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

Successfully merging this pull request may close these issues.

3 participants