新建用例数据类,用于动态修改测试数据
对应yaml文件,第一层结构为列表 第二层结构为具体序列化class对象
测试成功
public class TestYaml {
@ParameterizedTest()
@MethodSource
public void testDDTFromYaml(User user) {
assertTrue(user.name.length() > 3);
}
static List<User> testDDTFromYaml() throws IOException {
//创建objmapper
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
TypeReference typeReference = new TypeReference<List<User>>() {
};
//读取useryaml
List<User> users = mapper.readValue(
TestYaml.class.getResourceAsStream("/user.yaml"),typeReference
);
return users;
}
}
动态修改测试用例
@ParameterizedTest
@MethodSource
public void testDDTFromJson(User user) {
assertTrue(user.name.length() > 3);
}
static List<User> testDDTFromJson() throws IOException {
//创建objmapper
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
TypeReference typeReference = new TypeReference<List<User>>() {
};
//读取useryaml
List<User> users = mapper.readValue(
TestYaml.class.getResourceAsStream("/user.json"),typeReference
);
return users;
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章