I am trying to print the stack trace of the exception.
However, for negative test case, only the unexpected exception is printed.
I am using the @Rule ExpectedException to do the exception detection.
I don’t know how to add handling logic in case an unexpected exception is thrown.
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void myTest() throws Exception {
thrown.expect(MyException.class);
thrown.expectMessage("expected message");
}
Can’t you simply catch the exception within your test method, and then print the stack trace? (and then even rethrow it if you want).