3

I have a single Listener class that implements IAnnotationTransformer, IInvokedMethodListener, ITestListener and IReporter.

My Test run successfully BUT i get a warning "[TestNG] [WARN] Ignoring duplicate listener : com.NGtest.RetryListener". This warning is shown for every method call i.e. Listener gets called multiple times per test method invocation, and hence the IGNORED duplicate warning.

  • How to stop this warning from showing?
  • It is noted that if i remove the IReporter implementation then the warning is gone.
  • If i create different classes for each listener implementation then the warning is gone.
  • However, the plan was to have a single class implementing all the listeners. Is it possible?
  • How to solve this warning? Is this warning something to be concerned about? How can i stop this warning from showing?

Listener Class:

public class RetryListener implements IAnnotationTransformer, IInvokedMethodListener, ITestListener, IReporter {
    .....implemented methods for interface ....
}

Test Class:

public class RetryProvider {
    @Test (dataProvider = "datasource")
    public void Test1(int code, String type, ITestContext context){
        System.out.println("Test1(): " + code + " : " + type);
    }

    @DataProvider(name = "datasource")
    public Object[][] getData(){
        Object[][] data = new Object[3][2];
        data[0][0] = 1;
        data[0][1] = "apple";
        data[1][0] = 2;
        data[1][1] = "mango";
        data[2][0] = 1;
        data[2][1] = "guava";
        return data;
    }       
}

Test Xml:

...<suite name="NGBug Suite">
    <listeners><listener class-name="com.NGtest.RetryListener" /></listeners>
    <test name="NGBug Test"><classes><class name="com.NGtest.RetryProvider" /></classes>
    </test>
</suite>

Test Result:

[TestNG] [WARN] Ignoring duplicate listener : com.NGtest.RetryListener
[TestNG] [WARN] Ignoring duplicate listener : com.NGtest.RetryListener
[TestNG] [WARN] Ignoring duplicate listener : com.NGtest.RetryListener
Test1(): 1 : apple
Test1(): 2 : mango
Test1(): 3 : guava
Bipo K
  • 395
  • 3
  • 20
  • What version of TestNG are you using? – Robby Cornelissen Mar 27 '17 at 03:59
  • @RobbyCornelissen, I am using TestNG 6.11. – Bipo K Mar 27 '17 at 05:02
  • The problem originates with this commit: https://github.com/cbeust/testng/commit/9393c688aaa027a4e4dfa56cd70dfabc44db81b3 If you really want to get this fixed, best to raise an issue at the TestNG GitHub project. – Robby Cornelissen Mar 27 '17 at 05:15
  • 1
    Thank you @RobbyCornelissen for your time. I have raised the problem at TestNG GitHub [https://github.com/cbeust/testng/issues/1400](https://github.com/cbeust/testng/issues/1400) – Bipo K Mar 27 '17 at 06:45
  • @BipoK - Please refer to my comment in the bug that you logged. Please share a sample test that I can execute to recreate the problem. – Krishnan Mahadevan Mar 28 '17 at 03:24
  • @KrishnanMahadevan, done. have updated [https://github.com/cbeust/testng/issues/1400](https://github.com/cbeust/testng/issues/1400) with the sample. – Bipo K Mar 28 '17 at 11:46
  • @KrishnanMahadevan, one last question. Since there is a `WARNing`, Is there something to be concerned about if i continue to implement multiple listeners in the same class **OR** do you recommend separate class for each Listener i want to implement. Warning is shown only when i include `IReporter ` as one of the interfaces. Thanks again. – Bipo K Mar 28 '17 at 12:15
  • 1
    @BipoK - I don't think there should be any problem. But that being said, I would recommend that you have multiple listener implementations which target a specific Listener. That way you are will to wire them separately as and however you need. – Krishnan Mahadevan Mar 28 '17 at 13:42

0 Answers0