We have a unit tests parent Base class, and a set of unit tests extending the base class. I want every failing test to call a particular method. Is is possible to create a “hook” or something somewhere, i.e. passing tests do not call this method, but failing tests do at the end of execution.
Share
You should look at TestWatcher class.
Create your own class extending TestWatcher, override the failed(Throwable e, Description description) method and add a rule to your test.
Your test :
There also useful method in TestWatcher, like starting() and finished()