Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a TestWatcher before the @After

I wanted to take a screenshot when a test fails, but, afterwords, run the @After method.

Is it possible to do so? With TestWatcher the method failed() runs after the @After.

Furthermore, I cannot pass the @After content to the TestWatcher finished() because I have a super.afterTest() to call in @After.

Any ideas?

like image 534
mors Avatar asked Nov 02 '22 17:11

mors


1 Answers

It's impossible for TestWacher methods finished() or failed() to run before the @after method given that TestWatcher is a base class for Rules.

Because of the way that rules are set up, you can't have a rule that comes after @before or before @after. You can think of rules like shells that you put on the test method. The first shell to go on is @before/@after. Thereafter the @rules are applied. (Reference @Troy in Apply '@Rule' after each '@Test' and before each '@After' in JUnit)

The execution order, for one @test, is as follows

@TestWatcher starting
@Before 
@Test
@After
@TestWatcher finished
like image 176
kgf3JfUtW Avatar answered Nov 15 '22 10:11

kgf3JfUtW