Preserve Order in TestNG
Preserve Order in TestNG will discuss about the order of test case execution in testNG. Usually the order of execution in the testNG will be alphabetical order. Means, if you not set any priority then it will execute the test cases in alphabetical order. In our previous blog (i.e.Prioritizing Tests in testng) we have seen how to use the priority attribute of @Test annotation to execute the test cases in our own order.
We will write the test cases how we want to execute but by default testNG will not execute in order how we have written. For this we need to use priority attribute for each and every test to execute the test cases in predefined order. But writing priority for each test case is tedious as we may have so many test cases in our test suite.
To overcome this problem, there is one more option called “preserve-order”in the testNG. We can use this attribute at suite level or test level. If you set this value to “true” then it will execute the tests which are mentioned in the order in testng,xml file. Means, it will now not execute the tests in alphabetical order.