Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit 4.11 get test result in @After

Tags:

java

junit

junit4

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.

like image 801
atamanroman Avatar asked Mar 31 '14 22:03

atamanroman


2 Answers

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.

like image 88
Matt Avatar answered Sep 29 '22 14:09

Matt


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();
    ....
like image 45
djangofan Avatar answered Sep 29 '22 15:09

djangofan