Skip to main content

Claude/ChatGPT Prompt to Set Up Consumer-Driven Contract Tests

Set up Pact consumer-driven contract tests between two microservices with broker publishing, provider verification, and CI gating.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt frames the model as a senior test automation engineer setting up consumer-driven contract tests between [consumer_service] and [provider_service] using Pact, returning real config and code rather than pseudocode. Three placeholders shape it: [consumer_service], [provider_service], and [broker] (the Pact broker, with CI assumed to be GitHub Actions).

The structure works because the scariest microservice failures are silent API drift — the consumer assumes a field the provider quietly renamed. By asking for a consumer-side test that defines interactions and generates a pact file, publishing it with version and git-branch tags to [broker], provider-side verification with provider states, can-i-deploy gating, webhook or pending-pacts setup, and the GitHub Actions steps wiring it all together, the prompt makes the contract the source of truth. Gating deploys on can-i-deploy is what blocks a breaking change before release. Naming [consumer_service] and [provider_service] keeps the interactions and provider states concrete, so the generated test describes a real expectation between two specific services rather than an abstract example.

When to use it

  • You split a system into services and worry about silent API drift between teams.
  • You want a consumer-side Pact test that generates a pact file from expected interactions.
  • You need provider-side verification replaying the pact against [provider_service] with provider states.
  • You want can-i-deploy gating so a breaking change is blocked before release.
  • You need pact publishing to [broker] tagged with version and git branch.
  • You want pending-pacts so new contracts do not immediately break the provider build.

Example output

Expect separate code blocks: the Pact config, the consumer test (defining expected interactions and generating a pact file), the provider verification (replaying the pact against [provider_service] with provider states), and the GitHub Actions steps. The CI wiring covers publishing the pact to [broker] with version and git-branch tags, can-i-deploy gating to block breaking changes, and webhook or pending-pacts setup so new contracts from [consumer_service] do not fail the provider build immediately.

Pro tips

  • Gate deploys on can-i-deploy — a green unit suite means nothing if the contract between [consumer_service] and [provider_service] broke.
  • Tag published pacts with version and git branch so the broker can reason about which environments are compatible.
  • Use pending pacts so a brand-new contract does not immediately fail the provider build before the provider implements it.
  • Define provider states carefully; verification replays interactions against [provider_service], and missing states cause false failures.
  • Keep the consumer test focused on the interactions you actually depend on, not the provider's entire surface area.
  • Run can-i-deploy in both directions so a provider change is also checked against existing consumers, not just the consumer against the provider.
  • Wire the webhook so a provider verification result triggers re-checks, keeping the broker's compatibility picture current as either side ships.

Frequently Asked Questions

What does can-i-deploy actually prevent?
It blocks a release when the consumer and provider contracts are incompatible. Even if both services pass their own unit tests, can-i-deploy checks the broker and stops a deploy that would break the agreed interaction between them.
Will adding a new contract break the provider build?
Not if you use the pending-pacts or webhook setup in deliverable five. New contracts are treated as pending so the provider build does not fail immediately, giving the provider team time to implement before the contract is enforced.
What is the Pact broker for?
The `[broker]` stores published pacts tagged with version and git branch, coordinates provider verification, and powers can-i-deploy. It is the shared source of truth that lets both teams reason about which versions are safe to deploy together.
Does this assume a specific CI provider?
The prompt wires everything into GitHub Actions specifically, providing the CI steps for publishing, verification, and gating. The Pact concepts apply elsewhere, but the generated CI steps target GitHub Actions as written.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in Testing & QA Automation Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support