JUnit @Test expected annotation not working

前端 未结 8 1686
孤城傲影
孤城傲影 2020-12-05 17:46

I\'ve got the following test:

@Test(expected = IllegalStateException.class)
public void testKey() {
    int key = 1;
    this.finder(key);
}
<
8条回答
  •  余生分开走
    2020-12-05 17:56

    No, this JUnit test should work as it is - there is nothing more needed on this side.

    What makes you sure that the test throws an IllegalStateException? Is it possible that it gets wrapped into another exception of different type?

    Please post the exact failure message from JUnit.

    As @duffymo suggested, it is easy to verify what (if any) exception the test really throws.

提交回复
热议问题