public class Test {
protected String testPath = Paths.get("src", "test", "resources").toAbsolutePath().toString() + "/";
@DataProvider(name = "testData")
public Object[][] getData() throws Exception {
return Files.asCharSource(Paths.get(testPath, "csv", "test.csv").toFile(), Charsets.UTF_8)
.readLines()
.stream()
.map(line -> {
String[] array = line.split(",");
Object object1 = new Object();
object1.setProperty(Strings.emptyToNull(array[1]));//设置对象属性和相关data
Object object2 = new Object();
object1.setProperty(Strings.emptyToNull(array[2]));
Object object3 = new Object();
object1.setProperty(Strings.emptyToNull(array[3]));
return new Object[]{array[0], object1, object2, object3};
})
.toArray(Object[][]::new);
}
@Test(dataProvider = "testData")
public void test(String cid, Object object1, Object object2, Object object3) {
//do Something
//断言
}
}
csv 和DataProvider用法
最新推荐文章于 2024-04-12 23:17:53 发布