TestNG listener ordering is not guaranteed.
If you are keen on ordering the listeners that were created by you (and not by others), then you can do something like this:
- Define your own interface (in simple terms you can merely extend the TestNG listener that you are interested in).
- Create implementations for your interface that you defined in step (1)
- Use the Service Provider Interface (Service Loaders approach) to create a text file whose file name matches the interface in (1)
- Create 1 generic TestNG listener implementation that implements all the listeners which you extended in (1)
- Wire in this listener (which was created in (4)) using any one of the mechanisms [ either via "@Listeners" (or) via <listeners> (or) via Service Loaders ]
- Now within (5) include logic to load the listeners that were injected via SPI [ as explained in step (3) ]
- Within (5) internally iterate through all the implementations that you wired in [ step (3) ] and call them in the order ]that you desire.
Basically, what I am suggesting is that you need to create one orchestrating listener [ which will be invoked by TestNG] and this orchestrating listener will invoke the other listeners that you need in the order in which you need them to be invoked ]
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/