sbabcoc / TestNG-Foundation

TestNG Foundation is a lightweight collection of TestNG listeners, interfaces, and static utility classes that supplement and augment the functionality provided by the TestNG API.
Apache License 2.0
13 stars 5 forks source link

Ability to specify several Annotation transformers #3

Closed ghost closed 6 years ago

ghost commented 6 years ago

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?

sbabcoc commented 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.

yaroslav-orel commented 6 years ago

@sbabcoc I need to be able to add new annotation transformers via SPI mechanism so that they applied to every test class automatically.

sbabcoc commented 6 years ago

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?

yaroslav-orel commented 6 years ago

Superclass is not so convinient as SPI.

sbabcoc commented 6 years ago

Ok, but does it work?

sbabcoc commented 6 years ago

That question is a request for you to try attaching your annotation transformer to the listener chain to see if it works properly.

ghost commented 6 years ago

@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.

sbabcoc commented 6 years ago

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.

ghost commented 6 years ago

@sbabcoc this looks like exactly what I need. I'll try it out and report back to you later.

sbabcoc commented 6 years ago

@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.

yaroslav-orel commented 6 years ago

@sbabcoc Will do at the start of the next week.

yaroslav-orel commented 6 years ago

@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?

sbabcoc commented 6 years ago

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.

yaroslav-orel commented 6 years ago

@sbabcoc this is a decent workaround. Tried it today. Worked like charm. Think we can close this issue