0

I have a package with 2 classes.

My testng.xml looks like this:

<test name="Tests">
 <packages>
   <package name="PackageName"/>
 <packages>
</test>

Class2 always runs first followed by Class1.

I want to run Class1 first followed by Class2. Is this possible from this package level configuration?

Thanks, your answers and pointers are appreciative.

Eajaz
  • 469
  • 4
  • 21

2 Answers2

1

Use preserve-order="true" attribute at suite level. Also as specified in the testng's documentation

By default, TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictible order, set the preserve-order attribute to false

So I would suggest you specify your test classes instead of package
EDIT1: In that case run your testng tests programmatically.. Create testng.xml file on the fly by using reflection and adding all the classes to the testng.xml and then run that file
EDIT2: Java reflections is what you should be looking at..Sharing code may not possible for me now.. but this should get u started: Get Classes from a package {Java}

Community
  • 1
  • 1
Mrunal Gosar
  • 4,595
  • 13
  • 48
  • 71
  • Thanks @Mrunal...The point is there are so many classes in a package, and I would not like to expand my testng.xml file. :( – Eajaz May 05 '16 at 17:39
  • In that case run your testng tests programmatically.. Create testng.xml file on the fly by using reflection and adding all the classes to the testng.xml and then run that file – Mrunal Gosar May 06 '16 at 05:58
  • Sounds promising. Could you share any code snippet kind of? – Eajaz May 06 '16 at 06:11
  • check edit2..also you can refer into TestNG's code as well..we do something like that there as well. – Mrunal Gosar May 06 '16 at 08:22
0

By design, TestNG doesn't specify any specific order and it may change between versions.

But it should not be a problem because tests into different classes are supposed to be independant.

juherr
  • 5,640
  • 1
  • 21
  • 63