Testing for multiple exceptions with JUnit 4 annotations

后端 未结 7 2289
-上瘾入骨i
-上瘾入骨i 2020-12-30 22:06

Is it possible to test for multiple exceptions in a single JUnit unit test? I know for a single exception one can use, for example

    @Test(expected=Illega         


        
7条回答
  •  庸人自扰
    2020-12-30 22:38

    Although this is not possible with JUnit 4, it is possible if you switch to TestNG, which allows you to write

    @Test(expectedExceptions = {IllegalArgumentException.class, NullPointerException.class})
    

提交回复
热议问题