contract-testing
它能做什么
这项技能说明如何编写测试,描述前端对后端的预期,然后检查后端是否满足这些预期。适合前端与后端分开部署的团队。
适用场景
- ✓当前后端的改动经常相互破坏时。
- ✓当端到端测试因为两个服务必须同时运行而缓慢且脆弱时。
- ✓当你想知道两个服务能否独立部署时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/contract-testing/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在我的前端应用与其 API 之间设置契约测试,使有破坏性的后端改动能在 CI 中被发现。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会为 API 客户端添加 Pact 使用方测试,把预期的契约发布到 broker,并在后端流水线中加入提供方验证。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Implement consumer-driven contract testing for API boundaries
Integration tests that require both services running at the same time are slow, brittle, and hard to maintain. Consumer-driven contract testing decouples the consumer and provider test suites — each team can run their tests independently, yet the broker guarantees that the published contract is always verified against the live provider. This catches API mismatches days earlier than end-to-end tests, with far less infrastructure overhead.
Quick Reference
- The consumer writes tests that describe what it expects from the API (the "contract")
- The contract is published to a Pact Broker and verified against the real provider
- Provider changes that break the contract fail CI before they are deployed
- This replaces fragile end-to-end tests that require both services to be running simultaneously
Check
Check whether the frontend has consumer-driven contract tests that define and verify the API contract with the backend.
Fix
Add Pact consumer tests for the frontend API client, publish the contracts to a broker, and add provider verification to the backend CI pipeline.
Explain
Explain how consumer-driven contract testing works, what the Pact workflow looks like end-to-end, and how it compares to mocking and end-to-end testing.
Code Review
Review the Pact consumer tests. Flag interactions that are too permissive (any-type matchers on fields the consumer actually uses), missing status code assertions, and interactions for endpoints the consumer no longer calls.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/testing/contract-testing
常见问题
什么是契约测试?
记录前端对 API 的预期,并用这些预期检查真实 API 的测试。
这项技能使用哪个工具?
Pact,并使用 Pact Broker 来共享契约。
它和端到端测试有什么不同?
这项技能说明,契约测试不需要两个服务同时运行,并且能更早发现不匹配的问题。
详情
作者的原始描述
Use when setting up integration testing for a frontend-backend API boundary, evaluating whether two services are safe to deploy independently, or replacing slow end-to-end tests with contract tests.
热度
- GitHub 星标
- 75k
- 排名
- #2787
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。