Preserver-order
If you want the classes and methods listed in this file to be run in an unpredictable order, set the preserve-order attribute to false.By default, TestNG will run your tests in the order they are found in the TestNG.XML file.
Lets create three java class
First preserverOrderClass1 Class file
package testngexp;
importorg.testng.annotations.Optional;
importorg.testng.annotations.Parameters;
import org.testng.annotations.Test;
publicclass preserverOrderClass1 {
@Test
publicvoidTestMethod1(){
System.out.println("This TestMethod1");
}
@Test
publicvoid TestMethod2(){
System.out.println("This TestMethod2");
}
@Test
publicvoid TestMethod3(){
System.out.println("This TestMethod3");
}
@Test
publicvoid TestMethod4(){
System.out.println("This TestMethod4");
}
}
Second preserverOrderClass2 Java class
package testngexp;
import org.testng.annotations.Test;
publicclass preserverOrderClass2 {
@Test
publicvoid TestMethod1(){
System.out.println("This pTestMethod1");
}
@Test
publicvoid TestMethod2(){
System.out.println("This pTestMethod2");
}
@Test
publicvoid TestMethod3(){
System.out.println("This pTestMethod3");
}
}
Third preserverOrderClass3 Class file
package testngexp;
import org.testng.annotations.Test;
publicclasspreserverOrderClass3{
@Test
publicvoid pTestMethod1(){
System.out.println("This ppTestMethod1");
}
@Test
publicvoid pTestMethod2(){
System.out.println("This ppTestMethod2");
}
}
TestNG.xml file
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none"verbose="1"timeOut="1000">
<parametername="MethodName1"value="SuiteTagTestMethod1"/>
<testname="Test1"preserve-order="false">
<classes>
<classname="testngexp.preserverOrderClass1"/>
<classname="testngexp.preserverOrderClass2"/>
<classname="testngexp.preserverOrderClass3"/>
</classes>
</test><!-- Test -->
</suite><!—Suite -->
Results
Here, Preserver-order is given as false, so the execution of the order is unpredictable, PreserverOrderClass1 is executed first then PreserverORderClass3 then last PreserverORderClass3 is executed.
Note :If you are not given preserver-order or given as true,
it will execute PreserverOrderClass1 first then PreserverOrderClass2 then
PreserverOrderClass3 means how they define in TestNG.xml file.
Results look like below when user added preserver-order is true
Results
Comments
Post a Comment