3

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(){}
3

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() 
    {
        System.out.println("Method-1");
    }
    @Test(groups={"Smoke Test"})
    public void method2() 
    {
        System.out.println("Method-2");
    }

    @Test(groups={"Smoke Test"})
    public void method3() 
    {
        System.out.println("Method-3");
    }

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

    @Test(groups={"Regression"})
    public void method5() 
    {
        System.out.println("Method-5");
    }
    @Test(groups={"Regression"})
    public void method6() 
    {
        System.out.println("Method-6");
    }
    @AfterGroups("Regression")
    public void runfinal2() 
    {
        System.out.println("Regression Test End..");
    }

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

}

OUTPUT:

Launching URL
Method-1
Method-2
Method-3
Smoke Test End..
Method-5
Method-6
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
===============================================

TestNGGroup

  • 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 Jan 11 '17 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 Jan 11 '17 at 11:42
1

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.

0

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");
}
@Test
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 Jan 11 '17 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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