testNG is not executing all the methods inside the testng.xml file

/testng is not executing all the methods mentioned inside the class attribute.testng is allowing to add multiple methods attribute inside the class attribute.While running it will execute only the last methods mentioned in testng xml(methodname2)/

<suite name="test" verbose="1">
  <test name="test-Testing">
    <classes>
      <class name="com.qa.testcases.test">
        <methods>
          <parameter name="name" value="name"></parameter>
          <parameter name="description" value="description"></parameter>
          <include method="methodname1" />
        </methods>
        <methods>
          <parameter name="name1" value="name1"></parameter>
          <parameter name="description1" value="description1">/parameter>
            <include method="methodname2" />
        </methods>
      </class>
    </classes>
  </test>
</suite>

Upvotes: 0

Views: 1306

Answers (1)

tim-slifer
tim-slifer

Reputation: 1088

I think the issue is that you have two <methods> nodes inside your <class> node. However, while I can't find anything that explicitly states that two <methods> nodes is invalid, I can anecdotally say that I've never seen or used a TestNG XML file with such a format.

What I'm seeing is two test methods to be executed each with their own set of parameters. My recommendation is to simply reorganize your XML just a bit. I would suggest one of two options (though these are certainly not the only valid options):

One would be to break the XML into two <test> nodes, each running one of the methods with it's own set of parameters.

<suite name="test" verbose="1">
<test name="test-Testing1">
    <parameter name="name" value="name"></parameter>
    <parameter name="description" value="description"></parameter>
    <classes>
        <class name="com.qa.testcases.test">
            <methods>
                <include method="methodname1" />
            </methods>
        </class>
    </classes>
</test>
<test name="test-Testing2">
    <parameter name="name1" value="name1"></parameter>
    <parameter name="description1" value="description1">/parameter>
    <classes>
        <class name="com.qa.testcases.test">
            <methods>
                <include method="methodname2" />
            </methods>
        </class>
    </classes>
</test>
</suite>

With the above, you may need to revisit your configuration annotations (@Before/After) with small adjustments as needed (keep in mind that the annotations map to XML nodes in TestNG).

The second option would keep everything in one <test> node, then relying on each @Test method to use the appropriate @Parameters annotation to pick up the correct parameters from the XML.

<suite name="test" verbose="1">
<test name="test-Testing">
    <parameter name="name" value="name"></parameter>
    <parameter name="description" value="description"></parameter>
    <parameter name="name1" value="name1"></parameter>
    <parameter name="description1" value="description1">/parameter>
    <classes>
        <class name="com.qa.testcases.test">
            <methods>
                <include method="methodname1" />
                <include method="methodname2" />
            </methods>
        </class>
    </classes>
</test>
</suite>

With the above, methodname1() in your code would require an @Parameters annotation that calls name and description, while methodname2() would call name1 and description1.

From here, you can get more creative with the XML layout, but this should get you started. More info can be found here.

Upvotes: 1

Related Questions