depends on method in testng

In TestNG tests, we can have a test depending on another test or tests. Let us say we have 2 tests – testOrder and setup. Before executing the testOrder test, we want setup test method should be executed. Then we can use dependsOnMethods parameter as shown in below example. Please note that setup method is in same class as that of testOrder. But you can have a test that depends on test from different class or package. You will need to provide fully qualified name of the test as shown in below line.
 
@Test(dependsOnMethods = {"setup","org.softpost.AppTest.test2"})

Here is the example that illustrates the dependsOnMethods feature in TestNG.
 
package org.softpost;

import org.testng.annotations.Test;

public class DependencyTests {

    @Test(dependsOnMethods = {"setup"})
    public void testOrder(){
        System.out.println("testing order");
    }

    @Test
    public void setup(){
        System.out.println("setting up test");
    }
}

Here is the output of above example.
 
[TestNG] Running:
C:UsersSagar.IdeaIC15system	emp-testng-customsuite.xml
setting up test
testing order

===============================================
Default Suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================   

Web development and Automation testing

solutions delivered!!