TestNG @Test attributes - run by priority

to prioritize test case execution order, testng provides priority keyword and thew value starts from
1 to n...

For a method less priority number, executes first

test case   priority              
   tc1            2                     Order of execution
   tc2            4                            tc3 - tc1 - tc2 - tc4
   tc3            1
   tc4            5

Let's see the code implementation:

import org.testng.annotations.Test;

public class TestngAnnPriority {

 //priority starts from 1 to n
 @Test(description="This is testcase1 desc", priority=7)
 public void test1()
 {
  System.out.println("This is method: test1");
 }
 
 @Test(description="This is testcase2 desc", priority=5)
 public void test2()
 {
  System.out.println("This is method: test2");
 }
 
 @Test(description="This is testcase3 desc", priority=3)
 public void test3()
 {
  System.out.println("This is method: test3");
 }
}
OutPut
This is method: test3
This is method: test2
This is method: test1
PASSED: test3
        This is testcase3 desc
PASSED: test2
        This is testcase2 desc
PASSED: test1
        This is testcase1 desc

No comments:

Post a Comment