JUnit: Possible to 'expect' a wrapped exception?

后端 未结 7 1857
花落未央
花落未央 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:20

    The most concise syntax is provided by catch-exception:

    import static com.googlecode.catchexception.CatchException.*;
    
    catchException(myObj).doSomethingNasty();
    assertTrue(caughtException().getCause() instanceof MyException);
    

提交回复
热议问题