0

If have the following:

Class A
{ 
  Method M(priority = 2)
}

Class B
{ 
  Method M(priority = 1)
}

Then Class B is going to be executed before Class A. How can I execute Class A first?

The XML file that I am using is:

<classes>
  <class name="com.Users.Admin_ManageUsers_AR"/>
  <class name="com.Users.Admin_ManageUsers_AR"/>
</classes>
RobC
  • 22,977
  • 20
  • 73
  • 80
Ahmad Odeh
  • 47
  • 2
  • 10
  • Possible duplicate of [Priority in TestNG with multiple classes](https://stackoverflow.com/questions/26632241/priority-in-testng-with-multiple-classes) – Grasshopper Dec 04 '17 at 14:40
  • Best practice is to have each test be independent of the others so being able to run them in any order should be preferred. – JeffC Dec 04 '17 at 15:38

4 Answers4

0

Use group-by-instances="true" inside test tag of the testng.xml

Define your xml like below:

<test name="ManageUsersTest" group-by-instances="true">
    <classes>
        <class name="com.Users.Admin_ManageUsers_AR.ClassA" />
        <class name="com.Users.Admin_ManageUsers_AR.ClassB" />
    </classes>
</test>
Ali Azam
  • 2,047
  • 1
  • 16
  • 25
0

I would go with group-by-instances as well as answered by others.

Alternatively, you could use groups and dependencies like this example in the documentation

<test name="ManageUsersTest">
  <groups>
    <dependencies>
      <group name="c" depends-on="a  b" />
      <group name="z" depends-on="c" />
    </dependencies>
  </groups>
</test>

The depends-on attribute contains a space-separated list of groups.

This gives you more control in case you have dependencies across classes.

HaC
  • 902
  • 12
  • 24
0

An implicit way to prioritise test class execution is to add an alphabetically ordered prefix in class names. Like, you have test classes named : login , checkout, logout. Then rename them as TC01_login , TC02_checkout , TC03_logout. This will automatically prioritise the test execution as per the TC_{serial_number}

Manmohan_singh
  • 1,776
  • 3
  • 20
  • 29
0

Use preserver-order in testng.xml file, then all classes will be executed in order provided in testng.xml

<test name="Regression" preserve-order="true">
<classes>
murali selenium
  • 3,847
  • 2
  • 11
  • 20