package junit;
public class JunitArrayList {
public static void main(String[] args) throws Exception {
int[] a = new int[]{7,3,5,960,23,45,67,1,8,34,56,81,4};
JunitArrayList j = new JunitArrayList();
int result = j.getLarger(null);
System.out.println(result);
}
public int getLarger(int[] a) throws Exception {
int b = 0;
if(a.length==||0null == a){
throw new Exception("数组的长度不能为零");
}else {
for(int i = 0; i <a.length; i++){
if(b < a[i]){
b = a[i];
}
}
}
return b;
}
}
我使用Junit测试了但是出错了
Junit的代码如下
package junit;
import junit.framework.Assert;
import junit.framework.TestCase;
public class JunitArrayListtest extends TestCase{
private JunitArrayList j;
@Override
public void setUp() throws Exception {
j = new JunitArrayList();
}
@Override
public void tearDown() throws Exception {
System.out.println("测试完成了");
}
public void testgetLager(){
Throwable tx = null;
//int[] a = new int[]{7,3,5,960,23,45,67,1,8,34,56,81,4};
a = null;
int result = 0 ;
try {
result = j.getLarger(null);
} catch (Exception e) {
tx = e;
System.out.println(e.getMessage());
//Assert.fail("数组长度不能");
}
Assert.assertEquals(Exception.class, tx.getClass());
Assert.assertEquals("数组的长度不能为零", tx.getMessage());
//Assert.assertEquals(960,result);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(JunitArrayListtest.class);
}
}
请问为什么会出错啊请各位大侠不吝赐教
|