-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
As a user, I should be allowed to determine the order in which TestNG listeners will be invoked in my project (irrespective of whether those listeners were authored by me or if they were just getting resolved via some dependency).
TestNG currently has no way of ensuring that listeners are invoked in any specific order. The only round about approach that exists today is to build a container listener which would internally get all the listeners that a user wants to be registered within it and then it internally orchestrates execution of those listeners in a user determined fashion.
But this approach has a lot of pitfalls. Users have no control on listeners that were injected into TestNG via their classpath dependencies.
To mitigate all of this, TestNG should be able to do something like below:
- User defines a comparator that basically takes in two listener objects (implementations of ITestNGListener)
- Using the comparator the user determines the execution order.
- User plugs in this comparator as a configuration (or) as a special listener. The special listener path if taken would mean that this listener can only have 1 instance per TestNG execution.
- TestNG uses this new comparator to determine order and reverse-order for regular listeners and also for dealing with all reporters (including the TestNG default ones).
- TestNG should NOT apply this comparator logic to special listeners (the notion of special listeners were introduced into TestNG as part of this commit and should be available in the next upcoming TestNG version (
7.8.0perhaps?)
For more context, refer to this discussion