API 測試入門:用 Postman 和 pytest 打造你的第一個 API 測試
API 測試是現代 QA 必備技能。從 HTTP 基礎概念到實際用 Postman 和 pytest 寫測試,帶你踏出 API 測試的第一步。
本文範例使用假設的 API 端點,實際測試時請替換為你的目標 API。
為什麼要學 API 測試?
-
›
更快
不需要等頁面載入,直接測後端邏輯
-
›
更穩定
不受 UI 改版影響
-
›
更早測
前端還沒做好就能測後端
-
›
更容易自動化
純資料交換,不需要處理 UI 元素
HTTP 基礎快速複習
用 Postman 開始測試
-
›
建立 Collection
把相關 API 分組管理
-
›
設定環境變數
dev / staging / production 切換
-
›
寫測試腳本
在 Tests tab 用 JavaScript 驗證回應
-
›
用 Runner 批次執行
一次跑完所有測試案例
用 pytest 寫 API 測試
API 測試檢查清單
-
›
狀態碼驗證
確認回應的 HTTP 狀態碼正確
-
›
回應格式
JSON schema 是否符合規格
-
›
欄位驗證
必要欄位是否存在、資料型別是否正確
-
›
錯誤處理
是否回傳有意義的錯誤訊息
-
›
認證授權
認證和授權機制是否正常
-
›
效能
回應時間是否在可接受範圍內
The transformation of QA’s role in agile teams: from gatekeeper to quality coach
QA Practical Guide to Agile Transformation - the role change from gatekeeper to quality coach, covering QA responsibilities in the Scrum ceremony, collaboration model with development, and Definition of Done formulation methods
QA 工程師的一天:從手動測試到自動化的完整流程
分享 QA 工程師的日常工作,從需求分析、測試案例設計、手動測試執行到自動化測試導入的完整經驗。
Shift-Left Testing Strategy: A practical method to find bugs earlier and at lower cost
Shift-Left Testing Strategy Practice Guide - Advance testing to the early stages of development, covering requirements review, TDD, static analysis, Code Review and other methods to fundamentally reduce software defects and repair costs
General Disclaimer
The information provided on this site is for reference only. We do not guarantee its completeness or accuracy. Users should determine the applicability of the information on their own.