教程

学习 API 测试

本教程从什么是 API 讲起,最后讲到负载测试和 CI 流水线。前七课不需要会编程。之后,一些示例会用到 JavaScript 或 Python,每个都足够短,可以直接复制运行。

课程中的每个请求都发往一个真实的 API:https://api.testingapis.com。 它接受写入,并且有专门以特定方式失败的端点,因此你可以练习那些在别处难以复现的问题。大多数示例都有一个“发送”按钮,可以直接在本页运行请求。前几课使用不需要账户的端点;后面的课程需要一个免费账户,登录后它们的“发送”按钮即可使用。

19 课3 个级别免费

入门

7 课

什么是 API、HTTP 如何工作,以及如何发送请求并读懂返回的内容。

  1. 01什么是 API客户端、服务器,以及你早已在不知不觉中发出的请求。
  2. 02请求的结构方法、URL、请求头和请求体,以及服务器实际收到的内容。
  3. 03读懂响应状态码、响应头和响应体。
  4. 04HTTP 方法GET、POST、PUT、PATCH 和 DELETE,以及其中哪些可以安全地重复。
  5. 05读懂 JSONJSON 的六种类型,以及会让测试栽跟头的值。
  6. 06用 curl 和 Postman 发送请求你每天都会用到的两个工具,以及何时该选哪一个。
  7. 07编写你的第一批测试用例预期结果、反向测试、边界值和等价类。

进阶

7 课

正确地测试真实端点:CRUD、校验、身份验证、请求头,以及用代码编写的测试。

  1. 08端到端测试一个资源创建、读取、更新和删除,并检查每一步是否真的发生了。
  2. 09测试校验和错误错误的输入、缺失的字段、错误的类型,以及好的错误是什么样子。
  3. 10筛选、排序和分页那些直到第 3 页才有人注意到的列表端点 bug。
  4. 11Authentication and authorizationBasic auth, API keys, bearer tokens and JWTs, and the difference between 401 and 403.
  5. 12Headers, caching and cookiesContent negotiation, ETags, 304 responses and session cookies.
  6. 13Automating tests with codeTurning manual checks into tests with JavaScript or Python.
  7. 14Schemas and contract testingChecking the shape of a response, and using an OpenAPI document as the source of truth.

高级

5 课

只在生产环境中出现的故障:超时、异步任务、安全漏洞和负载。

  1. 15Timeouts, retries and rate limitsFlaky servers, idempotency keys, 429 responses and how clients should behave.
  2. 16Async jobs, webhooks and streamsTesting work that finishes later, requests the server sends to you, and open connections.
  3. 17Security testing basicsBroken object access, auth bypasses, mass assignment and injection.
  4. 18Performance testingMeasuring latency, reading percentiles and running a small load test.
  5. 19Running tests in CITest data, flaky tests, pipelines and deciding what to test at all.