JUnit @Test expected annotation not working

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

    i tried this one, and work perfectly as expected.

    public class SampleClassTest {
        @Test(expected = ArithmeticException.class )
        public void lost(){
            this.lost(0);
        }
        private void lost(int i) throws ArithmeticException {
            System.out.println(3/i);
        }
    }
    

    also ensure that junit4 is added as dependancy, @ (annotations) are new feature in junit 4.

提交回复
热议问题