JUnit: Possible to 'expect' a wrapped exception?

后端 未结 7 1862
花落未央
花落未央 2020-12-05 12:43

I know that one can define an \'expected\' exception in JUnit, doing:

@Test(expect=MyException.class)
public void someMethod() { ... }
         


        
7条回答
  •  青春惊慌失措
    2020-12-05 13:23

    You could wrap the testing code in a try / catch block, catch the thrown exception, check the internal cause, log / assert / whatever, and then rethrow the exception (if desired).

提交回复
热议问题