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

Confusing error message when the length of two multidimensional arrays are not equal #803

Closed
mattj256 opened this issue Jan 19, 2014 · 5 comments

Comments

@mattj256
Copy link

Current behavior:

assertArrayEquals((new Object[1][3]), (new Object[1][4]));
// throws ArrayComparisonFailure with message:
// "array lengths differed, expected.length=3 actual.length=4"

If I got this message I would assume that the FIRST dimension was different, but in this example it's the second dimension that's different. Is anyone bothered by this?

@devslash-paul
Copy link

This is expected behaviour for a JUnit test. The first is the expected and the second argument is the comparison. Therefore in this case the expected.length = 3 and actual.length = 4 when the inner array in the 2D array is being checked for length

@kcooney
Copy link
Member

kcooney commented Dec 22, 2014

Can anyone on this thread suggest a better error message?

@Stephan202
Copy link
Contributor

If the two arrays at depth N have different lengths, then that's just another instance of two elements at depth N - 1 being unequal. We already have code to construct a nice error message for this situation, in the form of the ArrayComparisonFailure class.

Thus, I claim the error message for the given example should simply be this:

arrays first differed at element [0]; array lengths differed, expected.length=3 actual.length=4

If you agree, I can open a PR with this small fix:

$ git diff --stat
 src/main/java/org/junit/internal/ComparisonCriteria.java   | 11 +++++++++--
 src/test/java/org/junit/tests/assertion/AssertionTest.java | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

@kcooney
Copy link
Member

kcooney commented Dec 27, 2014

@Stephan202 sounds reasonable. Please make the pull request against the junit5 branch

@Stephan202
Copy link
Contributor

@kcooney: Cool, I opened #1054.

@kcooney kcooney closed this as completed in 3f0adea Jan 4, 2015
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

No branches or pull requests

4 participants