Buttondown来自创作者

Buttondown 用 Schemathesis 把 OpenAPI 文档变成找 bug 工具

Buttondown 介绍如何用基于属性的测试工具 Schemathesis 测试其 REST API:工具读取 Django Ninja 生成的 OpenAPI 文档,自动构造请求并校验响应,首条规则是客户端输入不得导致 500 错误。

生成的测试发现了例行用例漏掉的问题,例如一个年份为 0422 的异常日期直达 Postgres 引发 500,以及元数据中的空字节和超出 64 位范围的整数。团队据此收紧字段校验,把错误响应也写进接口契约。

要点

  • Schemathesis 依据 OpenAPI 自动生成请求。
  • 首条规则:客户端输入不得触发 500。
  • 发现异常日期直达 Postgres 的问题。
  • 元数据空字节和超大整数也被拦截。
  • 测试分快速和深度两种模式。

原文:Turning our OpenAPI schema into a bug finder

Example-based tests show that an endpoint handles the scenarios we know to test. Schemathesis probes the scenarios we did not think to write down.

阅读原文

收录于 。摘自官方博客的简短节选,著作权归原发布者所有。

查看全部