Search code examples
javatestngselendroid

How to use testng annotations in test cases?


  1. I have below defined scenario.
  2. I want to use testng annotation.
  3. I want to execute methodfortestcase1() as first.
  4. And then I want to execute testcase1() as second.
  5. And then I want to execute methodfortestcase2() as third.
  6. And then I want to execute testcase2() as fourth.
  7. I have tried with different combinations of testng annotations such as Before Suite,Beforeclass,Beforemethod and BeforeTest.
  8. But, I am not getting the correct order of the test executions.
  9. How can I use the annotation for below defined scenario?

My code will be like below:

1.methodfortestcase1()
2.testcase1()
3.methodefortestcase2()
4.testcase2()

Solution

  • To get the desired result you'll likely have to use a combination of @Test(priority) and dependsOnMethods. Keep in mind that when using dependsOnMethods that if a dependency method fails, the dependents will not be run.