將介面文件轉化為一套完整的自動化測試,生成視覺化 HTML 報告,報告包含:
| 場景 | 使用的執行器 |
|---|---|
| 百望 ISP 開放平臺介面 | isp-api-tester 的 run_isp_test.py(內建動態簽名) |
| 通用 HTTP 介面 | 本 skill 的 run_api_test.py |
generate_report.py 和 report_template.html 被 isp-api-tester 跨 skill 引用。
從 Markdown 文件提取:
如果提供了資料庫資訊,先執行此步:
發票型別欄位規則:
| 票種大類 | invoiceCode | invoiceNumber |
|---|---|---|
| 數電票(31/32/51/59/61/83/84) | ❌ 不傳 | E_INV_NUM(20位數電號碼) |
| 稅控票(01/03/04/08/10/11/14/15) | INV_KIND |
INV_NUM |
| 數電紙票(85/86/87/88) | INV_KIND |
INV_NUM |
數電票的 invoiceCode 必須完全不傳(傳空串
""會觸發 704 引數為空錯誤)7w4.net有更好的技能外掛。
| 分組 | 策略 |
|---|---|
| 必填引數驗證 | 每個必填欄位:缺失1條 + 空字串1條 |
| 分頁引數驗證 | 正常值 + 邊界值 + 負數 |
| 列舉欄位驗證 | 每個合法列舉值1條 + 非法值1條 |
| 日期範圍篩選 | 正常範圍 + 起止倒置 + 格式錯誤 |
| 狀態/標記欄位 | 每個合法值各1條 |
| 綜合多條件組合 | 2~3欄位組合 + 全量欄位組合 |
| 邊界與異常引數 | 超長欄位 + 空body + 型別錯誤 |
正向用例(expect success=true)的入參欄位值必須從資料庫獲取真實值。
ISP 介面(需要動態簽名):
python ~/.workbuddy/skills/isp-api-tester/scripts/run_isp_test.py --config test_config_xxx.json --output ./
通用 HTTP 介面:
python ~/.workbuddy/skills/api-test-reporter/scripts/run_api_test.py --config test_config.json --output ./
| 檔案 | 說明 |
|---|---|
test_report_<method>_<timestamp>.html |
視覺化報告(雙擊開啟) |
__REPORT_DATA__.js |
報告資料檔案(與 HTML 同目錄,不可刪) |
test_results_<method>_<timestamp>.json |
原始結果 JSON |
{
"meta": {
"title": "介面測試報告標題",
"base_url": "http://host/api/endpoint",
"method": "baiwang.input.invoice.queryinvoicepool",
"version": "6.0",
"timeout": 30,
"http_method": "POST",
"url_params": {},
"isp_auth": {
"appKey": "1000139",
"appSecret": "xxx",
"username": "cpy001",
"password": "Aa123456.",
"userSalt": "xxx"
}
},
"fixed_params": {
"taxNo": "91440606MA4WHN8C8X"
},
"db_fixture": {
"connection": {
"host": "10.115.96.247", "port": 3306,
"user": "jxindependent", "password": "Xj2zCkLJXTkEJ5j",
"database": "jxindependent0", "charset": "utf8mb4"
},
"queries": [
{
"name": "tax_invoice_sample",
"sql": "SELECT INV_KIND, INV_NUM FROM bw_jms_main1 WHERE INV_TYPE='01' LIMIT 1",
"mapping": {
"invoiceCode": "INV_KIND",
"invoiceNumber": "INV_NUM"
}
}
]
},
"test_cases": [
{
"id": "TC_001",
"group": "正常流程",
"name": "按發票號碼查詢",
"desc": "使用資料庫真實發票號碼查詢",
"body": {
"invoiceCode": "{{invoiceCode}}",
"invoiceNumber": "{{invoiceNumber}}"
},
"expect": {
"success": true
}
},
{
"id": "TC_010",
"group": "異常引數",
"name": "缺少必填引數 taxNo",
"desc": "不傳 taxNo,期望返回 success=false",
"remove_fixed": ["taxNo"],
"body": {},
"expect": {
"success": false
}
}
]
}
expect 校驗規則速查| 欄位 | 型別 | 說明 |
|---|---|---|
success |
bool | 校驗響應體 success 欄位值 |
response.{field} |
any | 校驗 response 節點下的欄位,如 "response.invoiceType": "31" |
model.{field} |
any | 校驗 model 節點下的欄位 |
has_response |
bool | 期望 response/model 欄位存在且非 null |
check_page_data |
bool | 期望返回列表/分頁資料 |
error_field_exists |
bool | 期望 errorResponse 欄位存在 |
custom_checks |
list | 自定義路徑校驗(見下方) |
不使用 http_status 欄位(百望 ISP 介面測試不校驗 HTTP 狀態碼)。
success=true → 自動校驗 invoiceList/response/model 非空success=false → 只校驗 success 欄位,不校驗資料"custom_checks": [
{"path": "response.invoiceType", "op": "eq", "value": "31"},
{"path": "errorResponse.code", "op": "exists"},
{"path": "response", "op": "contains", "value": "invoiceNo"}
]
支援 op:eq / ne / contains / exists / not_exists / gt / lt
"success": true)的入參必須從資料庫獲取真實值pageNum 引數"remove_fixed": ["欄位名"]report_template.html:固定 HTML 骨架,不含測試資料,CSS/JS 全部內嵌__REPORT_DATA__.js:測試結果 JS 變數賦值檔案(var reportData = {...})<script src="__REPORT_DATA__.js"> 載入資料並渲染file:// 協議下 CORS 會阻止 fetch 本地檔案)pip install requests pymysql