Kovid Mehta
Kovid Mehta

Reputation: 561

TestNG test are not getting executed as per the priority

Below is my project structure in eclipse :

->testclasses

---->AccountTest(Priority of Methods from 1-6)

---->BillingTest(Priority of Methods from 7-13)

---->HomePageTest(Priority of the only method is 17)

---->SupportTest (Priority of Methods from 14-16)

All the test classes above have methods where priority is set in incremental order as shown above.

Now when I right click on testclasses package and run it as Testng. It starts the execution with HomePageTest.

I am setting the priority of my test methods as below :

@Test(priority=6, dataProvider="Setup")

I want the execution to be as per the priority defined for each method and Thus method with priority 1 should execute first irrespective of which class it is in.

Upvotes: 4

Views: 2229

Answers (2)

Deepak Attri
Deepak Attri

Reputation: 132

TestNG runs test cases in order of the priorities. If there is no priority for a testmethod then by default TestNG sets the priority to 0. In your case, in HomePageTest class there may be some method with priority 0. Either set priority of all the methods or use test methods in xml runner file to run in a given order

 <test name="DummyTest">
  <classes>
     <class name="apitestset.inventory.Test">
                <methods>
                    <include name="create"/>
                    <include name="update"/>
                    <include name="get"/>
                    <include name="check"/>
                    <include name="initiate"/>
                    <include name="confirm"/>
                    <include name="extend"/>
                </methods>
            </class>
<classes>

Here testclass has 7 methods and they run in the order given in xml runner file. Don't set the priority if you are using methods in xml runner file.

Upvotes: 0

Sameer Arora
Sameer Arora

Reputation: 4507

The correct way to run all the tests present in multiple classes with priorities is to run those by a testng file. So write all the classes name in the testng.xml file and then run the testng file by right clicking on it from the package explorer--> Run As-->TestNG Suite. Your test cases will run according to the priorities set irrespective of the classes they belong to.

You testng.xml should look like:

<test name="TestSuiteName">
    <classes>
        //Insert the whole path of the classes here like
        <class name="packageName.AccountTest" /> 
        <class name="packageName.BillingTest" />
        <class name="packageName.HomePageTest" />
        <class name="packageName.SupportTest" />
    </classes>
</test>

Upvotes: 1

Related Questions