How test runner prioritize test classes for execution in Selenium?


We can prioritize tests in TestNG during execution. It must be noted that priority can only be set for test methods with @Test annotation. Lower the priority number set for a test method, higher the priority it gets during execution.

Only integer value (positive, zero or negative) can be set as priority. A decimal number can also be set as priority, however it is required to be converted to integer value via typecasting.

A test method cannot have multiple priority numbers. Also, the priority for a test method cannot be set from the TestNG XML file.

Syntax

public class TestNG {
   @Test (priority = 2)
   public void tC1() {
      System.out.println("Test Case 1");
   }

Example

import org.testng.annotations.Test;
public class TestNGP {
   @Test (priority = 2)
   public void testCase1() {
      System.out.println("This is the A Normal Test Case 1");
   }
   @Test (priority = 1)
   public void testCase2() {
      System.out.println("This is the A Normal Test Case 2");
   }
   @Test (priority = 3)
   public void testCase3() {
      System.out.println("This is the A Normal Test Case 3");
   }
}

Output

Updated on: 07-Apr-2021

536 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements