1.新建一个factory
public class TestFactory {
@DataProvider(name="userpass")
public Object[][] userdata() {
return new Object[][]{{"zhangsan","123456"},{"lisi","111111"}};
}
@Factory(dataProvider="userpass")
public Object[] TestFactory(String username,String userid) {
return new Object[]{new UserTest(username,userid)};
}
}
2.创建usertest的class
public UserTest(String username,String userid) {
this.username = username;
this.userid = userid;
}
@Test
public void login(){
System.out.println("login with username = "+username+"and userid = "+userid);
}
@Test
public void publish(){
System.out.println("publish with username = "+username+"and userid = "+userid);
}
}
3.执行结果,这样可保证多用户执行用例时数据不错乱
结果
网友评论