testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.98k stars 1.02k forks source link

ITestNGListenerFactory is broken and never invoked #3120

Open RiJo opened 5 months ago

RiJo commented 5 months ago

TestNG Version

7.10.2

Worked as expected in 7.8.0

Expected behavior

When a ITestNGListenerFactory implementation is registered via @Listeners annotation, ITestNGListenerFactory#createListener should be invoked before any @Test annotated methods are invoked.

Actual behavior

ITestNGListenerFactory#createListener is never invoked.

Is the issue reproducible on runner?

Test case sample

  1. Factory is part of test class:

    @Listeners(FactoryListenerTest.class)
    public class FactoryListenerTest implements ITestNGListener, ITestNGListenerFactory {
    
    @Override
    public ITestNGListener createListener(Class<? extends ITestNGListener> listenerClass) {
        // Never invoked
        System.out.println("FactoryListenerTest.createListener");
        return null;
    }
    
    @Test
    public void test() {
        System.out.println("FactoryListenerTest.test");
    }
    }
  2. Independent factory

    
    public class CustomFactory implements ITestNGListener, ITestNGListenerFactory {
    
    @Override
    public ITestNGListener createListener(Class<? extends ITestNGListener> aClass) {
        // Never invoked
        System.out.println("CustomFactory.createListener");
        return null;
    }
    }

@Listeners(CustomFactory.class) public class FactoryListenerTest {

@Test
public void test() {
    System.out.println("FactoryListenerTest.test");
}

}



### Contribution guidelines

Incase you plan to raise a pull request to fix this issue, please make sure you refer our [Contributing](.github/CONTRIBUTING.md) section for detailed set of steps.
krmahadevan commented 5 months ago

Root cause of this issue was because of this PR https://github.com/testng-team/testng/pull/3060

krmahadevan commented 5 months ago

@RiJo - Until this issue is fixed, can you please try adding


<properties>
   <property>
      <name>listenerfactory</name>
      <value>your.fully.qualified.classname.goes.here</value>
  </property>
</properties>

This should ensure that your listener factory gets invoked when you run your tests using maven.

For running tests via intellij you can set this configurmation via the Test runner params

image
RiJo commented 5 months ago

Thanks for the quick response!

It is not possible for me to add custom parameters and/or properties as the TestNG tests are part of a larger system. I will stay on version 7.8.0 until the issue has been addressed. Thanks!