package GroupDependencyTest;
import org.testng.annotations.Test;
public class TestApp {
//Run if all methods from "deploy" and "db" groups are passed.
@Test(dependsOnGroups={"deploy","db"})
public void method1() {
System.out.println("This is method 1");
//throw new RuntimeException();
}
//Run if method1() is passed.
@Test(dependsOnMethods = { "method1" })
public void method2() {
System.out.println("This is method 2");
}
}
package GroupDependencyTest;
import org.testng.annotations.Test;
public class TestDatabase {
//belong to "db" group,
//Run if all methods from "deploy" group are passed.
@Test(groups="db", dependsOnGroups="deploy")
public void initDB() {
System.out.println("This is initDB()");
}
//belong to "db" group,
//Run if "initDB" method is passed.
@Test(dependsOnMethods = { "initDB" }, groups="db")
public void testConnection() {
System.out.println("This is testConnection()");
}
}
package GroupDependencyTest;
import org.testng.annotations.Test;
//all methods of this class are belong to "deploy" group.
//Run the tests on the order specified in group
@Test(groups="deploy")
public class TestServer {
@Test
public void deployServer() {
System.out.println("Deploying Server...");
}
//Run this if deployServer() is passed.
@Test(dependsOnMethods="deployServer")
public void deployBackUpServer() {
System.out.println("Deploying Backup Server...");
}
}
testng.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestDependency">
<test name="TestCase1">
<classes>
<class
name="GroupDependencyTest.TestApp">
</class>
<class
name="GroupDependencyTest.TestDatabase">
</class>
<class
name="GroupDependencyTest.TestServer">
</class>
</classes>
</test>
</suite>
No comments:
Post a Comment