Search code examples
javajunitunhandled-exception

In JUnit, will @After method run, when @Test method throws an exception which is unhandled?


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?


Solution

  • 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.