接口测试用例
接口测试用例创建¶
在 Postman 中,创建测试集,填写接口信息,通过调参和编写断言结果来测试搜索接口。
测试集创建¶

接口测试用例创建¶
根据接口测试用例
- 选择请求方法为 GET 请求
- URL 为:https://spring-petclinic-rest.k8s.hogwarts.ceshiren.com/petclinic/api/owners
- 添加请求参数:lastName=Green

添加断言:
在 Postman 中编写断言信息,发送请求,得到断言结果:
// 验证响应状态码
pm.test("响应状态码为 200", function () {
pm.response.to.have.status(200);
});
// 验证响应信息是否包含某字段
pm.test("响应体中包含预期的字符串", function () {
pm.expect(pm.response.text()).to.include("Green");
});
// 验证响应头信息中的 Content-Type 是否存在
pm.test("Content-Type is present", function () {
pm.response.to.have.header("Content-Type");
});

点击 Send 按钮运行接口,查看结果

保存接口到测试集

选择新创建好的测试集,点击 SAVE 按钮

运行测试集¶
把请求参数定义为测试集变量

接口中的请求参数替换为变量

准备 json 格式测试数据
[
{
"lastName": "Green",
"expect": "Green"
},
{
"lastName": "",
"expect": ""
},
{
"lastName": "a",
"expect": "a"
},
{
"lastName": "b",
"expect": "b"
},
{
"lastName": "A",
"expect": "A"
},
{
"lastName": "hogwarts",
"expect": "hogwarts"
},
{
"lastName": "hogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwarts",
"expect": "hogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwartshogwarts"
},
{
"lastName": "涨",
"expect": "涨"
},
{
"lastName": "123",
"expect": "123"
},
{
"lastName": "###",
"expect": "###"
}
]
接口中的断言替换为测试数据中的值
// 验证响应信息是否包含某字段
pm.test("响应体中包含预期的字符串", function () {
pm.expect(pm.response.text()).to.include(data.expect);
});
进入测试集运行页面

选择测试数据文件,延迟时间,保存响应
