由于Junit中没有对数组比较的断言,因此自定义了以下断言:
/**
* asserts two String arrays are equal。
*/
public static void assertEquals(final String[] expected,
final String[] actual)
{
if(expected == null && actual == null)
{
assertTrue(true);
}
else if(expected.length != actual.length)
{
fail("expected length is :" + expected.length + "but was:"
+ actual.length);
}
else
{
for(int i = 0; i < expected.length; i++)
{
assertEquals("第" + (i + 1) + "个元素不相等", expected[i], actual[i]);
}
}
}
可是又怎么对该方法进行测试呢?
|