Saturday, 23 June 2018

TestNG Priority and Sequencing

Hi everyone, in this post we will see how to priorities Test cases in TestNG and how to sequence it as per our requirement. If you create a test class and add multiple test cases and run it then each time test case execution sequence is randomly selected .
With TestNG annotations @Test and parameter "priority" we can define sequence and priority for executing test cases. Let us consider the below example and if you run the test class given below multiple times you can see that each time execution sequence/flow is different hence to define a fixed execution flow we user TestNG annotation priority.

Video Tutorial -



package test;
import org.testng.annotations.Test;
 
public class TesNGSequencing {
 
 
 
  @Test
 
  public void One() {
 
      System.out.println("Test Case number One");
 
  }
 
  @Test
 
  public void Two() {
 
   System.out.println("Test Case number Two");
 
  }
 
  @Test
 
  public void Three() {
 
   System.out.println("Test Case number Three");
 
  }
 
  @Test
 
  public void Four() {
 
   System.out.println("Test Case number Four");
 
  }
 
}

Given below is the example for using priority annotations. When you run the below test class then each time execution flow is constant and starts with test case having 0 priority.


package test;
import org.testng.annotations.Test;
 
public class TesNGSequencing {
 
 
 
  @Test(priority=0)
 
  public void One() {
 
      System.out.println("Test Case number One");
 
  }
 
  @Test(priority=1)
 
  public void Two() {
 
   System.out.println("Test Case number Two");
 
  }
 
  @Test(priority=2)
 
  public void Three() {
 
   System.out.println("Test Case number Three");
 
  }
 
  @Test(priority=3)
 
  public void Four() {
 
   System.out.println("Test Case number Four");
 
  }
 
}

Skipping a Test -


If you come across a situation where there is requirement to skip some tests then in this case you can do it using @Test annotations and enabled parameter.




package test;
import org.testng.annotations.Test;
 
public class TesNGSequencing {
 
 
 
  @Test(priority=0, enabled=false)
 
  public void One() {
 
      System.out.println("Test Case number One");
 
  }
 
  @Test(priority=1)
 
  public void Two() {
 
   System.out.println("Test Case number Two");
 
  }
 
  @Test(priority=2)
 
  public void Three() {
 
   System.out.println("Test Case number Three");
 
  }
 
  @Test(priority=3)
 
  public void Four() {
 
   System.out.println("Test Case number Four");
 
  }
 
}

6 comments:

  1. AWS Training in Bangalore - Live Online & Classroom
    myTectra Amazon Web Services (AWS) certification training helps you to gain real time hands on experience on AWS. myTectra offers AWS training in Bangalore using classroom and AWS Online Training globally. AWS Training at myTectra delivered by the experienced professional who has atleast 4 years of relavent AWS experince and overall 8-15 years of IT experience. myTectra Offers AWS Training since 2013 and retained the positions of Top AWS Training Company in Bangalore and India.


    IOT Training in Bangalore - Live Online & Classroom
    IOT Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Reading data through the sensors and processing it with applications sitting in the cloud and thereafter passing the processed data to generate different kind of output is the motive of the complete curricula. Students are made to understand the type of input devices and communications among the devices in a wireless media.

    ReplyDelete
  2. Great Article. Thank you for sharing! Really an awesome post for every one.

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

    ReplyDelete