0

我从未用 JUnit 测试过,不知道在这种情况下我必须做什么

@Test(expected = ArrayIndexOutOfBoundsException.class)
public void throwsArrayIndexException() {
    ...
}

我只需要测试一下,如果 main 方法中的 args[0]==0,ArrayIndexOutOfBoundsException 是预期的,我尝试了 if(args[0]==0){throw new ArrayIndexOutOfBoundException} 但没有用..我很感激你帮助!提前致谢!

4

1 回答 1

0
@Test(expected = ArrayIndexOutOfBoundsException.class) 
public void throwsArrayIndexException() {
  int [] array = new int[] {};
  int num = array[1];
}
于 2021-01-21T05:33:10.160 回答