0
  • I'm assigning priority to each test method in a specific class under my automation project.
  • My senior reviewed the script I wrote and mentioned to me that do not use priority instead use the xml to order the execution of the methods.
  • I wanted to know if using priority for each method is a good approach or not.
  • I had an issue before regarding the order in which the methods were getting executed. That's why i started using the priority technique.
  • If someone has suggestions please help me to understand it. I'm new to programming language and automation
2

Using priority to drive order of execution is perfectly fine, but question is why do you want to execute test cases in certain order? As a general rule test case should be atomic and should not be dependent on another test cases. In such case do you worry about order of execution. I rather don't pay much attention to order of execution unless its an explicit requirement. e.g. If my login test case fails then I don't want to execute rest of test cases in suite as those will likely fail. In such a situation, I would use hard dependency to drive.

@Test 

public void serverStartedOk() {} 

@Test(dependsOnMethods = { "serverStartedOk" }) 

public void method1() {} 

You can also have methods that depend on entire groups:

@Test(groups = { "init" }) 
public void serverStartedOk() {} 
@Test(groups = { "init" }) 

public void initEnvironment() {} 
@Test(dependsOnGroups = { "init.*" }) 

public void method1() {} 

You can also use soft dependency to drive execution order. By "alwaysRun=true" in your @Test annotation.

Know more at TestNG site.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.