Testing for multiple exceptions with JUnit 4 annotations

后端 未结 7 2306
-上瘾入骨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条回答
  •  猫巷女王i
    2020-12-30 22:32

    How would you expect to "expected"s to work? A method can only throw one exception.

    You would have to write a different unit test for each way the method can fail. So if the method legitimately throw two exceptions then you need two tests set up to force the method of throwing each exception.

提交回复
热议问题