1

Problem - I have 6 tests and one dataprovider with 2*2 object array.

I want TestNG to pick first data, use it in First test and then subsequent tests are executed based on the data picked in first test.

In the second iteration testng picks second data and all the subsequent tests should iterate as per priority.

Issue - Right now I tried prioritizing and pointing @dataprovider for each test but first test is executed twice (2 iterations) and then it moves to second test, now second test executes twice and so on.

Please let me know the solution.

1

You have to change the approach to what you consider your tests.

The best practice is to have each test independent from each other. What you're describing is that each test somehow accounts the state set on previous test otherwise the order would not matter.

To achieve the effect described in your question you have to introduce the only one test in your test class (a method annotated as a test). All other 6 tests are to be converted to just a regular methods and are to be called in required order from that your single test method.

So the composition would be the following:

  • method1
  • method2
  • ...
  • method6
  • test
    • call method1
    • call method2
    • call ...
    • call method6
  • 1
    Thanks Alexey, Finally, you got my problem and I think I have to change my approach as my tests are dependent, This seems to me a satisfactory approach. – viki Aug 1 '18 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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