以下是在Linux系統下使用Postman設計接口測試用例的步驟:
Content-Type
、Authorization
)。// 驗證狀態碼為200
pm.test("Status code is 200", () => pm.response.to.have.status(200));
// 驗證響應體中字段存在且類型正確
pm.test("Response has user ID", () => {
const data = pm.response.json();
pm.expect(data.id).to.be.a('number');
});
```。
base_url
、token
),在請求中通過{{變量名}}
引用,便于切換測試環境。newman run collection.json -e environment.json -r html --reporter-html-export report.html
```。
Pre-request Script
或Tests
腳本提取前一個接口的返回值,作為后續請求的參數。參考來源: