import java.util.ArrayList;
import java.util.List;
import org.testng.annotations.Factory;
public class DynamicTestPlanTest {
TestPlan1 obj1;
TestPlan2 obj2;
@Factory
public Object[] setUp() throws Exception {
List list=new ArrayList();
int a=30,b=20;
if(a>b){
obj1=new TestPlan1();
list.add(obj1);
}else{
obj2=new TestPlan2();
list.add(obj2);
}
Object[] data = list.toArray();
return data;
}
}
package FactoryAnnotation;
import org.testng.annotations.Test;
public class TestPlan1{
@Test
public void testPlan1Method1()throws Exception {
System.out.println("testPlan1Method1- invoked");
}
@Test
public void testPlan1Method2()throws Exception {
System.out.println("testPlan1Method2 - invoked");
}
@Test
public void testPlan1Method3()throws Exception {
System.out.println("testPlan1Method3- invoked");
}
@Test
public void testPlan1Method4()throws Exception {
System.out.println("testPlan1Method4 - invoked");
}
}
package FactoryAnnotation;
import org.testng.annotations.Test;
public class TestPlan2{
@Test
public void testPlan2Method1()throws Exception {
System.out.println("testPlan2Method1- invoked");
}
@Test
public void testPlan2Method2()throws Exception {
System.out.println("testPlan2Method2 - invoked");
}
}
testng.xml
<suite name="DynamicTestPlanTestSuite" verbose="1" >
<test name="DynamicTestPlanTest" preserve-order="true">
<classes>
<class name="FactoryAnnotation.DynamicTestPlanTest"></class>
</classes>
</test>
</suite>
No comments:
Post a Comment