Dependency testing with TestNG

Dependency is an feature provided by TestNG which allows test methods to depend on a single or a group of test method. Suppose we have a situation when executing current method, we have a prerequisite to execute another method. At this situation , we can go for DependsonMethod feature.

TestNG DependsOnMethods Example 1 :

Output :

TestNG-DependsOnMethod-Example

When we execute the above program, since we have used
dependsonmethod attribute with Test annotation, testscript1 has
dependency with testscript2. Hence testScript2 will be executed first,later testscript1 will be executed.

TestNG DependsOnMethods Example 2 :

Output :

TestNG-DependsOnMethod-Exception

When we execute the above program,testScript2 will be failed which contains RunTimeException. Hence TestNG will skip the testScript1 method.

Leave a Comment

Your email address will not be published. Required fields are marked *