Home > OS >  Is there a way to set priorities among classes in TestNG?
Is there a way to set priorities among classes in TestNG?

Time:06-24

Is there a way to set priorities among classes execution in TestNG? Is there some annotation or xml settings? Thanks.

CodePudding user response:

It can be achieved in testng.xml file. Order of classes is important in the file, and just run directly this file.

CodePudding user response:

@Test(priority = 1) 
public void testMethodA() { 
   System.out.println("Executing - testMethodA");
} 
@Test 
public void testMethodB() { 
   System.out.println("Executing - testMethodB");
}
@Test(priority = 2) 
public void testMethodC() { 
   System.out.println("Executing - testMethodC");
}

Output

  1. Executing - testMethodB

  2. Executing - testMethodA

  3. Executing-testMethodC

testMethodB got executed first as it had a default priority of 0

  • Related