知识卡片
从规格生成模式用例
将 OpenAPI 作为生成自动检查的输入,可用同一份文档确定请求形态和响应断言。规格中的可用示例可以提高基础用例的可执行性。生成工具可检验状态码、媒体类型、模式和其他已声明的约束,亦可产出测试集合供团队审阅和流水线复跑。
覆盖范围取决于模式和例子、测试环境中的有效数据,以及前置业务状态是否准备好。深度场景仍可用定制代码,或显式关联已有操作以表达先创建再读取等步骤。将报错与对外契约对照,可发现容器或网关默认错误输出与约定不符。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 用模式测试检查 API 遵约 7.4 Generating schema tests · 查看原书依据
Rather than writing schema tests for each endpoint and each response type on an endpoint, what if you could generate the tests from the OpenAPI definition? With this approach, you can have a tool that generates and executes happy and sad path schema tests from the API definition against the API gateway or API service. Figure 7.3 illustrates how this would work.
参考来源
- 位置:《Automating API Delivery APIOps with OpenAPI》《第 07 章 用模式测试检查 API 遵约》(7.4 Generating schema tests;来源项目 book-source,extracted/Automating API Delivery APIOps with OpenAPI/_epub-src/OEBPS/Text/chapter-7.xhtml#p50)
- 结论依据:给出用 OpenAPI 自动创建并执行模式测试的基本做法。
- 原始内容:Rather than writing schema tests for each endpoint and each response type on an endpoint, what if you could generate the tests from the OpenAPI definition? With this approach, you can have a tool that generates and executes happy and sad path schema tests from the API definition against the API gateway or API service. Figure 7.3 illustrates how this would work.