1. 使用接口信息生成测试用例

我们将下面的Prompt输入DeepSeek模型,观察其返回结果。


根据提供的接口信息,生成接口测试用例,并以json格式返回。json格式需包含请求体、请求头。接口信息如下:

{ "API": "/payment", "method": "POST", "params": { "user_id": {"type": "int", "required": true, "min": 1000, "max": 9999}, "amount": {"type": "float", "required": true, "min": 0.01, "max": 10000.00}, "currency": {"type": "enum", "values": ["USD", "CNY", "EUR"]}, "timestamp": {"type": "timestamp", "format": "ISO8601"} } }

返回结果如下


{ "test_cases": [ { "description": "正常请求(所有参数有效)", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 1000, "amount": 50.5, "currency": "USD", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "缺少必填参数 user_id", "headers": { "Content-Type": "application/json" }, "body": { "amount": 50.5, "currency": "CNY", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "user_id 小于最小值 (999)", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 999, "amount": 0.01, "currency": "EUR", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "user_id 超过最大值 (10000)", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 10000, "amount": 10000.0, "currency": "USD", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "user_id 非整数类型", "headers": { "Content-Type": "application/json" }, "body": { "user_id": "1000a", "amount": 50.5, "currency": "USD", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "amount 小于最小值 (0.00)", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 2000, "amount": 0.00, "currency": "CNY", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "amount 超过最大值 (10000.01)", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 3000, "amount": 10000.01, "currency": "EUR", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "amount 为负数 (-50.0)", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 4000, "amount": -50.0, "currency": "USD", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "amount 非数字类型", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 5000, "amount": "fifty", "currency": "CNY", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "currency 无效值 (JPY)", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 6000, "amount": 500.0, "currency": "JPY", "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "timestamp 格式错误", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 7000, "amount": 750.0, "currency": "EUR", "timestamp": "2023-10-05 12:34:56" } }, { "description": "可选参数 currency 缺失", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 8000, "amount": 800.0, "timestamp": "2023-10-05T12:34:56Z" } }, { "description": "可选参数 timestamp 缺失", "headers": { "Content-Type": "application/json" }, "body": { "user_id": 9000, "amount": 900.0, "currency": "USD" } } ] }

从返回结果来看,DeepSeek成功生成了我们期望的测试用例。这些测试用例可以直接用于编写接口测试脚本,我们只需将DeepSeek返回的结果传递给测试脚本即可。

当然,根据实际需求,预期结果可能需要进行微调,但接口返回的状态码通常是可以直接使用的。此外,我们还可以在Prompt中预先定义接口返回的枚举值,以便DeepSeek生成更精确的测试用例。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐