Prioritizing Test Case

We can set the ‘priority’ parameter for any test case. With the help of this, we can set the execution order of the test cases.

Let us see an example:

package testFramework;

import org.testng.annotations.Test;

public class PriorityTests {

  @Test(priority = 2)
  public void LogoutApp() {
    System.out.println("This is Logout page");
  }

  @Test(priority = 0)
  public void LoginApp() {
    System.out.println("This is Login page");
  }
  
  @Test(priority = 1)
  public void InTheApp() {
    System.out.println("This is in the app page");
  }
}

 

Output:
priority-test-output

Skipping Test Case

We can enable or disable test cases as per our need. In TestNG we use the ‘enabled’ parameter to apply this feature.

Let us see an example:

package testFramework;

import org.testng.annotations.Test;

public class PriorityTests {

  @Test(priority = 2, enabled = false)
  public void LogoutApp() {
    System.out.println("This is Logout page");
  }

  @Test(priority = 0)
  public void LoginApp() {
    System.out.println("This is Login page");
  }
  
  @Test(priority = 1)
  public void InTheApp() {
    System.out.println("This is in the app page");
  }
}

 

Output:

priority-tests-output