Alex Rivera | Logout

junit arrays not equal test

Asked 2011-09-05T08:34:14.497
49

I'm trying to write a test case where my scenario is that two byte arrays should be not equal.

Can I do this with junit?

Or do I have to use something external like Hamcrest? I couldn't change the code in this answer to do the job

Please give a sample.

Edit
Report

1 Answer

61

You can use

assertFalse(Arrays.equals(array1, array2));

If you wanted to check they were equal, I would use the following instead.

assertEquals(Arrays.toString(array1), Arrays.toString(array2));

as this produces a readable output as to what was different rather than just failing.

answered 2011-09-05T08:37:07.083

Your Answer