Closed ghost closed 6 years ago
Just add your annotation transforms to the chain - as many as you like! Let me know if you have issues with this approach.
@sbabcoc I need to be able to add new annotation transformers via SPI mechanism so that they applied to every test class automatically.
If you specify @LinkedListeners in one of your test classes, do its annotations get transformed? Can you declare a superclass for your test classes and specify @LinkedListeners there?
Superclass is not so convinient as SPI.
Ok, but does it work?
That question is a request for you to try attaching your annotation transformer to the listener chain to see if it works properly.
@sbabcoc I checked it recently and it works. But you're missing my point. I need to be able to specify list of annotation transformers in place which is not connected to specific test class. This needs to be independent place like SPI mechanism so that my annotation transformers are applied to every test class I run implicitly. Maybe the title of the issue is confusing. Please tell me if this needs to be defined in a separate issue as feature request.
Once a listener is linked into the chain, it applies to every class. However, your issue report got me to remember how annotation transforms work. These need to run prior to the instantiation of the test classes. Annotation transformers attached via the \@LinkedListeners annotation will never be called. I implemented a service loader in ListenerChain and deployed release 1.6.0 with this update. This new feature is documented in the README. Check it out and let me know how this works for you.
@sbabcoc this looks like exactly what I need. I'll try it out and report back to you later.
@da-yaroslav-orel - Have you been able to try out the latest release, to see if it provides the behavior you need? I'd like to close out this issue.
@sbabcoc Will do at the start of the next week.
@sbabcoc Thanks for the waiting. This approach partially works for me. It assumes I have control over listeners I add via SPI but on my project we add external annotation transformers as well and we cannot modify its source code to add 'implements LinkedListener'. Do you have any ideas how this situation can be handled?
The Service Loader is the deciding factor here. All of the classes specified in the 'services' data file must implement the interface indicated by the file name, which is the class name of the common base class (com.nordstrom.automation.testng.LinkedListener
in this case). You should be able to extend the class(es) that you don't own to add the LinkedListener
marker interface, even if you don't have the source code.
@sbabcoc this is a decent workaround. Tried it today. Worked like charm. Think we can close this issue
ListenerChain is annotation transformer. With this we cannot add our custom annotation transformers because TestNG allows only one annotation transformer applied. Can TestNG-Foundation implement multiple annotation transformer logic?