In JUnit, using TestWatcher and overriding the failed () function , is it possible to remove the thrown exception and instead make its own statement?
Use case: with functional tests on Android, when the test crashes the application, I would like to replace NoSuchElementException with AssertionError ("application crashed" ").
I have no problem creating a custom statement (when I detect a failure in the ready () method ), but how to remove the thrown exception?
Because in my report, it creates an exception and an assertion for one test, therefore there are more failures than the test on failure, which is logical, but annoying.
I was wondering if there is a way to set up a Throwable object to remove a specific NoSuchElementException by manipulating a stacktrace.
I did not succeed. (And I certainly don’t want to execute it with try / catch in every test ...).
Fanch source
share