I faced similar problem in my framework test classes. usually if we use both dependsOnMethods
or priority
in our test class testng executes test with priority first but doesn't apply priority to tests having dependsOnMethods
. Tests with 'dependsOnMethod' attribute will run in the last as per their dependencies/priorities. Test case execution order will be like below:
- Test cases without dependencies according to priorities.
- Test case with dependencies in order of test methods they are dependent on and priority.
Hence,In your case it will execute test cases having dependency on 'method1' first and than test case having dependency on 'method3'. To solve this problem you need understand in which sequence you tests are going to executed based on priorities
and dependsOnMethods
. You have to adjust both attributes accordingly. You can also make one test case dependent on multiple test methods for example in your case you can make test case 4 dependent on 'method1' as well as 'method3'.