我在单位测试中抛出一个例外,但是在投掷后,我仍然希望能够继续测试
doThrow(new Exception()).when(myMock).myMethod();
myMock.myMethod();
System.out.println("Here"); // this is never called
// Do verify and asserts
有可能执行此操作吗?
您可以发现例外:
doThrow(new MyException()).when(myMock).myMethod();
try {
myMock.myMethod();
fail("MyException should have been thrown!");
} catch (MyException expected) {
// Do something
}
System.out.println("Here");
// Verify the mock, assert, etc.