How will I make sure that my @After method runs even if @Test method throws an exception which is unhandled or this is actually internally done by JUnit?
JUnit runs methods annotated with @After
after each test case regardless of thrown exceptions.
To quote the JUnit documentation:
All @After methods are guaranteed to run even if a Before or Test method throws an exception.
Yes, an @After
method is always run, even if an exception is thrown in a @Test
method.
The test will fail if it isn't configured with @Test(expected=ExceptionClass.class)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With