2

I am lagging behind to understand the concept of dependsOnMethods and priority. I googled but I didn't get enough info about this. A one line answer will be greatly appreciated. Can we write multiple methods with the same priority?

1
  • 1
    When we use Depends On the subsequent methods will be skipped when your methods fail. In case of priority all the test cases will run. Commented Nov 19, 2018 at 10:32

2 Answers 2

5

Yes, definitely we can write multiple methods with same priority but disadvantage of using this-There is no guarantee which method will run first, So- Instead of this,you can use 'dependsOnGroups' annotation from TestNG which you can easily perform stepwise operations.

@Test(priority=1)
 public void Login() 
{ 
  System.out.println("LogIn Test code.");
  Assert.assertTrue(5>6, "Condition Is False.");
}

@Test(priority=1, dependsOnMethods={"Login"}) 
public void checkMail() 
{ 
  System.out.println("checkMail Test code.");
}

@Test(priority=1,dependsOnMethods={"Login","checkMail"}) 
public void LogOut() 
{ 
  System.out.println("LogOut Test code.");
}

----------------------
Instead of this you can use -'dependsOnGroups' annotation.

@Test(groups = { "A" })
   public void login() 
  {
      System.out.println("PrintMessage()");
  }
.
.
.
.

@Test(dependsOnGroups = { "A" }) 
public void LogOut() 
{ 
  System.out.println("LogOut Test code.");
}
3
  • Test(priority=1,dependsOnMethods={"Login","checkMail"}) how this will work ? is it execute login method then checkmail? Commented Apr 21, 2016 at 9:32
  • This test will run unless & until- "Login","checkMail" these two methods successfully run & pass. If one method gets failed last method i.e-logout test will not run. It means logout test is depends on both tests.
    – Bharat Mane
    Commented Apr 21, 2016 at 9:41
  • @sameer.....got it ? let me know if you have any doubts
    – Bharat Mane
    Commented Apr 21, 2016 at 9:43
2

Yes, you can write multiple methods with the same priority (quite similar to not use any priority - all methods has the same default priority). About dependsOn annotation in a few words:

dependsOnMethods

There is no guarantee on the order on which the methods depended upon will be run, but you are guaranteed that all these methods will be run before the test method that contains this annotation is run.

More complex answer you can find here: https://stackoverflow.com/a/36713748/4855333

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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