Is there any way I can get the test result in the teardown (@After
) method? I'd like to do clean up after the tests depending on the result.
Could not find much details about @After
in the junit docs.
The closest thing to what you're asking for would probably be the TestWatcher rule. That won't give you access to a returned result or anything, but you can use it (or create your own TestRule and combined with the Description object, you could annotate your methods differently to indicate what sort of clean-up is necessary.
Yes, if you use TestNG, it is a standard function, your @After method can look like this:
@AfterTest
public void cleanUp( ITestResult result ) {
boolean success = result.isSuccess();
....
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