0

I have never tested with JUnit, not sure what I have to do in this case

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

I just have to test that if args[0]==0 in main method, ArrayIndexOutOfBoundsException is expected, I tried with if(args[0]==0){throw new ArrayIndexOutOfBoundException} but didn't work.. I appreciate your help! Thanks in advance!

1 Answer 1

0
@Test(expected = ArrayIndexOutOfBoundsException.class) 
public void throwsArrayIndexException() {
  int [] array = new int[] {};
  int num = array[1];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hello and welcome to SO! While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. Please read the tour, and How do I write a good answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.