方法一
执行脚本:
import org.testng.annotations.Parameters;#注意要引入这个包
public class NewTestA {
@Test
@Parameters("test1") //设置测试方法的入参
public void b2(String test1) throws Exception {
System.out.println(test1);
Thread.sleep(5000);
}
}
xml配置设置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="lucax19" parallel="false">
<parameter name="test1" value="testng" />
<test name="lucax1901" >
<packages>
<package name="com.uuu"/>
</packages>
</test> <!-- Test -->
</suite> <!-- Suite -->
方法二:
执行脚本:
public class NewTestA {
//定义对象数组 这里分别会循环取数值取跑对应调用的测试用例
@DataProvider(name="user")
public Object[][] Users(){
return new Object[][]{
{"testingwtb","a123456"},{"testingwtb2","a1234561"}
};
}
@Test(dataProvider="user")
public void b2(String test1,String test2,String uu) throws Exception {
System.out.println(test1);
System.out.println(test2);
Thread.sleep(5000);
}
}
xml配置设置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="lucax19---------">
<test name="lucax1901" >
<packages>
<package name="com.uuu"/>
</packages>
</test> <!-- Test -->
</suite> <!-- Suite -->