JUnit @Test expected annotation not working

前端 未结 8 1683
孤城傲影
孤城傲影 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 18:08

    The problem was, that the class in which the test was nested was an extension of TestCase. Since this is JUnit 3 style, the annotation didn't work.

    Now my test class is a class on its own.

提交回复
热议问题