Suppose I have five test cases out of which three are grouped in "Smoke Testing" and two have not been grouped at all.

If I have set priority for all my test cases from 1 to 5, will the cases from smoke testing group be evoked in priority?

@Test (priority=3, groups={"Smoke Testing"})
p v Test1(){}
@Test (priority=1, groups={"Smoke Testing"})
p v Test2(){}
@Test (priority=2, groups={"Smoke Testing"})
p v Test3(){}
@Test (priority=5)
p v Test4(){}
@Test (priority=4)
p v Test5(){}

What will happen if I want to add another group XYZ and added test cases like:

@Test (priority=2, groups={"XYZ"})
p v Test6(){}
@Test (priority=1, groups={"XYZ"})
p v Test7(){}

4 Answers 4


I was created sample TestNG Class in which test cases are divided in 'Smoke test' and 'Regression' Groups.

package com.testNG;

import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;

public class TestNG_Groups 
    @BeforeGroups("Smoke Test")
    public void setup() 
        System.out.println("Launching URL");

    @Test(groups={"Smoke Test"})
    public void method1() 
    @Test(groups={"Smoke Test"})
    public void method2() 

    @Test(groups={"Smoke Test"})
    public void method3() 

    @AfterGroups("Smoke Test")
    public void runfinal1() 
        System.out.println("Smoke Test End..");

    public void method5() 
    public void method6() 
    public void runfinal2() 
        System.out.println("Regression Test End..");

    @Test(dependsOnGroups = {"Smoke Test","Regression"})
    public void tearDown() 
        System.out.println("Closing Browser");



Launching URL
Smoke Test End..
Regression Test End..
Closing Browser
PASSED: method1
PASSED: method2
PASSED: method3
PASSED: method5
PASSED: method6
PASSED: tearDown

    Default test
    Tests run: 6, Failures: 0, Skips: 0


  • Thanks a lot Bharat. You perhaps forgot to set priority attributes as was asked in the question. What if you have same priority to cases from both groups and to a test cases without any group. So here you have 3 different cases and we need to see the output. Will do that. Thanks again.
    – NiNa
    Commented Jan 11, 2017 at 10:55
  • 3
    Every time there is no need to assign priority for test cases, If Priority is not defined to any test cases in that case : test cases will executes in ascending orders of method name and you have to declare in that way for Ex: method: a1, xyz, p1, c1, m1 It will executes in ascending order like: a1-> c1-> m1-> p1-> xyz
    – Bharat Mane
    Commented Jan 11, 2017 at 11:42

TestNG doesn't care about groups at runtime. Then, it will only follow priority.

Groups are used for the test selection/filtering.

In other words: TestNG will always follow priority on selected tests and groups are a way to change the test selection.


Here is my version of story.

@Test(priority=2, groups={"Smoke"})
public void Test1(){
    System.out.println("Test 1 -priority=2, Smoke");
@Test(priority=4, groups={"Smoke"})
public void Test2(){
    System.out.println("Test 2 -priority=4, Smoke");
@Test(priority=1, groups={"Smoke"})
public void Test3(){
    System.out.println("Test 3 -priority=1, Smoke");
@Test(priority=2, groups={"Reg"})
public void Test4(){
    System.out.println("Test 4 -priority=2, Reg");
@Test(priority=3, groups={"Reg"})
public void Test5(){
    System.out.println("Test 5 -priority=3, Reg");
@Test(priority=4, groups={"Reg"})
public void Test6(){
    System.out.println("Test 6 -priority=4, Reg");
public void Test7(){
    System.out.println("Test 7");

The output is well explanatory and explains everything. The output is:

Test 7
Test 3 -priority=1, Smoke
Test 1 -priority=2, Smoke
Test 4 -priority=2, Reg
Test 5 -priority=3, Reg
Test 2 -priority=4, Smoke
Test 6 -priority=4, Reg
  • 3
    Finally, when there is a same prioritization for different test cases Like you have assigned priority=2 two times, so in this case the test cases will run ascending order of method name. If you are not agree with this try interchanging mathod name of 'void Test1' and 'Void Test4' and observe the result.
    – Bharat Mane
    Commented Jan 11, 2017 at 11:51

As evidenced by NiNa's answer above: Answer, Priority always takes precedence and it overrides the group mechanism (and as such, dependencies). If there are two methods with the same priority, the first one that goes is in alphabetical order. Additionally, and a little off topic, is that preserve-order in your TestNG.xml file seems to be the last of all the ordering mechanisms that is adhered, and behaves strangely (can't figure it out yet) when mixed with groups / priorities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.