【发布时间】:2019-07-12 08:14:49
【问题描述】:
这是我尝试为它编写 junit 测试用例的数组代码的串联,但它给出了语法错误。我不确定确切的语法是什么。
public static String[] concatArray(String[] firstArry, String[] secArry) {
if (null != firstArry && null == secArry) {
return firstArry;
} else if (null == firstArry && null != secArry) {
return secArry;
} else if( null != firstArry && null != secArry ){
String[] concatArry = new String[firstArry.length + secArry.length];
System.arraycopy(firstArry, 0, concatArry, 0, firstArry.length);
System.arraycopy(secArry, 0, concatArry, firstArry.length, secArry.length);
return concatArry;
}else{
return null;
}
JUnit 测试用例。
@Test
public void testConcatArray() {
String[] arr1 = {"nodename", "nodecategory"};
String[] arr2 = {" test"," case"};
Assert.assertEquals({"abc"}, StringUtils.concatArray(arr1, arr2));
}
【问题讨论】:
-
尝试使用 assertArrayEquals() 参见:stackoverflow.com/questions/3457941/…
-
我认为这是因为
{"abc"}这在 java 中无效