JUnit

Exception test

  • @Rule 어노테이션을 이용.
  • ExpectedException 에 원하는 Exception 클래스 추가
    • expect
    • expectMessage
    • expectCause
public class ExceptionTest {

    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    @Test
    public void nullPointExceptionTest() throws Exception {
        expectedException.expect(NullPointerException.class);

        // ... Something code
        String a = null;
        a.equals("b");
    }

}

results matching ""

    No results matching ""