artdanil
artdanil

Reputation: 5082

What are consequences of specifying different listeners in different parts of TestNG configuration?

Problem description:

The setup is executing Ant build script with TestNG target, which then loads testng.xml file. There is a possibility to specify listeners in both Ant file and testng.xml.

The questions arising are following:

  1. Will both set up ways be supported? Will all the listeners specified in both configuration location be used during test execution?
  2. Will any of listeners be prioritized over another? If yes, how?

Sample set up:

Ant file:

<project>
<property name="classes.dir" path="<my_classes_dir>" />
<property name="test.dir" path="<my_test_dir>" />
<target name="run-test">
    <testng useDefaultListeners="false"
          listeners="org.testng.reporters.EmailableReporter, org.testng.reporters.XMLReporter, com.example.MyCustomReporter">
        <classpath>
          <path path="${classes.dir}" />
        </classpath>
      <xmlfileset dir="${test.dir}" includes="testng.xml" />
    </testng>
</target>
</project>

TestNG.xml:

<suite name="MyTestSuite">
    <listeners>
        <listener class-name="com.example.MyListener" />
        <listener class-name="org.testng.reporters.FailedReporter" />
    </listeners>
    <test name="MyTest1">
        <classes>
            <class name="com.example.MyTest1" />
        </classes>
    </test>
</suite>

Background:

I have to support existing project which uses set up similar to the one described above. The Ant build file disables default reporters. Without touching Ant build file, I would like to specify additional report listeners (FailedReporter and/or any custom ones) for my tests in testng.xml.

Upvotes: 0

Views: 697

Answers (1)

niharika_neo
niharika_neo

Reputation: 8531

I believe all listeners should be run, in your build file as well as in your testng.xml. The testng.xml listeners would be executed second. If the same listener is listed in both, build file and testng.xml, it would be executed twice.

This is based on my experience with Maven, but I guess, with ant it should be the same. Also the order of listeners specified in testng.xml cannot be guaranteed in case both are implementing the same set of interfaces.

Hope it helps.

Upvotes: 1

Related Questions