How JUnit's assertArrayEquals() should be implemented

I find myself writing this assertion method at (almost) any project where #tests > K where K is typically 10. In other words: Every project.



public static void arrays(Object[] actual, Object... expected) {
for(int i = 0; i < Math.min(actual.length, expected.length); ++i)
Assert.assertEquals("Array mismatch at index " + i + ":", expected[i],
actual[i]);

Assert.assertEquals("Array length mismatch", expected.length,
actual.length);
}

2 comments :: How JUnit's assertArrayEquals() should be implemented

  1. Take a look at hamcrest. It has a multiple built-in matchers.

  2. Thanks for posting this blog. This was very interesting blog, I felt comfortable while reading this post, thank you..........................To knowOracle Training

Post a Comment