There are times when you need to run a test case when some other test case has executed. This scenario is attained by using dependency in testNG.
TestNG allows you to specify dependencies either with annotations or in XML.
TestNG allows you to specify dependencies either with:
- Using attribute dependsOnMethods in @Test annotations.
- Using attribute dependsOnGroups in @Test annotations.
Here is a brief example:-
package testNG;
import org.testng.annotations.Test;
public class Test
{
@Test (dependsOnMethods = {"h2"})
public void h1()
{
System.out.println("test case 1");
}
@Test
public void h2()
{
System.out.println("test case 2");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="softwaretestingmaterial">
<test name="testngTest">
<classes>
<class name="testNG.Test" />
</classes>
</test>
</suite>
Hope this helps.