Styrow.dev
Question 7 of 14
TestNG Topic: General medium

How do you prioritize your test case in TestNG?

Question

How do you prioritize your test case in TestNG?

Answer

You can set priority for TestNG @Test annotated methods as bellow.

@Test(priority=0)

Using priority, We can control @Test method execution manner as per our requirement. That means @Test method with priority = 0 will be executed 1st and @Test method with priority = 1 will be executed 2nd and so on.

Sample Code:

public class setPriorityExample{

@Test(priority=0) public void Test1(){ System.out.println(""This test will run first.""); }

@Test(priority=2) public void Test2(){ System.out.println(""This test will run third.""); }

@Test(priority=1) public void Test3(){ System.out.println(""This test will run second.""); } }