@After
will do what you want. According to the documentation :
All @After methods are guaranteed to execute, even if the Before or Test method throws an exception.
(This intuitively makes sense to me, since I imagine that the test method is completed in a try
block that will catch any exception and convert it to a test failure. Therefore, the test fails, then the break block is executed).
Note that it does not indicate that the method will be started if Error
is reset. Usually, if you only use the @After
method to maintain the state of the test, and this does not present a problem, because in this case there will be no tests. If you use any resources in the test that absolutely must be cleaned up (for example, your own interceptors), then it is best to do this in the try-finally
block in the test method itself.
source share