跳到正文
Skillpedia
测试75k · #2787

contract-testing

它能做什么

这项技能说明如何编写测试,描述前端对后端的预期,然后检查后端是否满足这些预期。适合前端与后端分开部署的团队。

适用场景

  • ✓当前后端的改动经常相互破坏时。
  • ✓当端到端测试因为两个服务必须同时运行而缓慢且脆弱时。
  • ✓当你想知道两个服务能否独立部署时。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/contract-testing/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/contract-testing/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2787
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能