TestNG XML execution order

Yuvraj

I have testng java project as below (in the exact order)

TestNGOnePack
 ClassOne.java
 ClassTwo.java

TestNGThreePack
 ClassOne.java
 ClassTwo.java

TestNGTwoPack
 ClassOne.java
 ClassTwo.java

each java file is as follows

@Test
public void pkgName()
{
    System.out.println(this.getClass().getCanonicalName());
}

testng.xml is as follows

<suite name="Suite One">
<test name="Test One" >
<classes>
 <class name="TestNGTwoPack.ClassTwo" />   
 <class name="TestNGOnePack.ClassOne" />
</classes>
    <packages>
         <package name="TestNGThreePack" />
   </packages> 
</test> 

when I ran this as testng I got the following output

TestNGTwoPack.ClassTwo
TestNGThreePack.ClassOne
TestNGOnePack.ClassOne
TestNGThreePack.ClassTwo

My question is the output's sequence is ambiguous Shouldn't it be as follows? what wrong here ??? what's the reason that the output is as above and not as below ??

TestNGTwoPack.ClassTwo
TestNGOnePack.ClassOne
TestNGThreePack.ClassOne
TestNGThreePack.ClassTwo
drkthng

No, unfortunately what you see is the currently implemented behaviour in testNG.

See this discussion to stay up to date.

Workaround

There are several methods to work around this issue, including groups and dependsOnGroups etc. that you can read about in the discussion above.


But in your case I think I would go for several suite-files and one "Master-Suite" that fires these suites, then you can be sure to have the right order of execution.

Your testng_packageAandB.xml:

<?xml version="1.0" encoding="UTF-8"?>

<suite name="Suite - package A and B">
    <test name="Test - package A and B">
        <classes preserve-order="true">
            <class name="drkthng.selenium_experiments.packageB.Class01" />
            <class name="drkthng.selenium_experiments.packageA.Class02" />
        </classes>
    </test>
</suite>

Your testng_packageC.xml:

<?xml version="1.0" encoding="UTF-8"?>

<suite name="Suite - package C">
    <test name="Test - package C">
        <packages preserve-order="true">
            <package name="drkthng.selenium_experiments.packageC" />
        </packages>
    </test>
</suite>

And your "run all" xml:

<?xml version="1.0" encoding="UTF-8"?>

<suite name="allSuites">
  <suite-files>
    <suite-file path="testng_packageAandB.xml" />
    <suite-file path="testng_packageC.xml" />
  </suite-files>
</suite>

Running only the last xml will give you an execution that you expect, in my case this one:

[TestNG] Running:
D:\JavaWorkspace\selenium-experiments\testng_packageAandB.xml

drkthng.selenium_experiments.packageB.Class01 drkthng.selenium_experiments.packageA.Class02

[TestNG] Running:
D:\JavaWorkspace\selenium-experiments\testng_packageC.xml

drkthng.selenium_experiments.packageC.Class01 drkthng.selenium_experiments.packageC.Class02

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related