I just noticed that jUnit 4.8.1 does not include support for testing two boolean arrays for equality. There are tons of other assertArrayEquals but none to take in two boolean arrays.
Is there a proper way to do this? My current thinking is that I’d have to iterate over an array and use something like
Assert.assertTrue(arrayOne[i] == arrayTwo[i]);
Is there a cleaner way to do this?
You can use
Arrays.equals()to compare the two arrays, then assert that they are equivalent.Arrays.equals()checks the length and each element in the array, so you won’t have to worry about iterating over each array.There is also
Assert.assertArrayEquals, which will give you the exact position that the arrays differed at.Example: for a test written as such:
The result would be: