We can set dependency in testNg by writing the paramter dependsOnMethods= in the @Test annotation.
Supposing you are testing online email application using selenium WebDriverand you have two @Test methods In your class : 1) For LogIn and 2) For Check Mail. Now due to the some reasons (Invalid credentials), LogIn @Test method fails. In this case you not need to execute Check Mail @Test method because how can you check emails without LogIn In email application? In this case, You can use dependsOnMethods with @Test annotation of Check Mail method to skip Its execution.
@Test
public void Login() {
Assert.assertTrue(5>6, "Condition Is False.");
}
@Test(dependsOnMethods={"Login"})
public void checkMail() {
System.out.println("checkMail Test code.");
}