JUnit @Test expected annotation not working

前端 未结 8 1660
孤城傲影
孤城傲影 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:59

    @RunWith(JUnit4.class)
    public class MyTestCaseBase extends TestCase 
    

    I also had problems with @Test(expected = ...) annotation when I extended TestCase class in my base test. Using @RunWith(JUnit4.class) helped instantly (not an extremely elegant solution, I admit)

提交回复
热议问题