0
votes

I have a testng suite file which has 10 classes inside a test. Say

<classes>
 <class name = "Class1">
 <class name = "Class2">
 <class name = "Class3">
</classes>

Now class1 has 3 methods with priority 1,2,3 in order and the same with class 2 and class3. When I run the job in Jenkins with suite having preserve-order="true", the tests run as class1-priority1 test, class2-priority1, class3-priority1, class1-priority2, class2-priority2 etc.

I need to have all the tests associated with class1 executed inorder first and then class2 and then class3.

Could someone tell me why this behavior is?

2
Please note, that TestNG in version 6.10 + changed policy regarding preserve-order and priority importance: "Hierarchy on order features (from less important to more important): groupByInstance, preserveOrder, priority, dependsOnGroups, dependsOnMethods"guitar_freak

2 Answers

0
votes

The default order depends on the Java reflection API. You may include method names under < methods > in the order you want. This may be cumbersome & may look clumsy while file gets bigger. Nevertheless, it may help you in this regard.

Example xml:

<class name="Fully qualified class name without extension">
    <methods>
       <include name="method_1" />
       <include name="method_1" />
            .....
            .....
        <include name="method_N" />
     </methods>
</class>

Other than the previous solution, you may add dependency for test cases in your test methods using annotation. But, changing/modifying xml will far better than modifying codes.

0
votes

The order you describe is the expected one.

Instead of priority, you should try to use dependsOnMethods.