JUnit 4.11 get test result in @After

java, junit, junit4

Solution

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.

Problem

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.

Original source