Project | Web & API, CI/CD

Pact Contract Testing

Consumer-driven contracts with Pact V4: matchers and provider states with parameters on the consumer side, JUnit 5 verification of the real Spring Boot app with pending and WIP pacts, and publish, can-i-deploy and record-deployment in GitHub Actions.

A TypeScript consumer and a Java Spring Boot provider, 6 interactions verified through a self-hosted Pact Broker; can-i-deploy blocks a breaking consumer change while the provider build stays green.

On this page
  1. Problem and purpose
  2. Architecture
  3. Technology and tools
  4. Engineering decisions and approach
  5. Test scope and execution approach
  6. Results with dated evidence
  7. Evidence explorer
  8. Local setup and execution
  9. Workflow and reports
  10. Known limitations

Problem and purpose

Shows how two teams can change and deploy their services independently without an end-to-end environment: the consumer writes down what it needs, the provider proves it delivers that, and the broker answers before every deployment whether the versions fit together. Two languages on purpose: the teams share only the contract.

Architecture

checkout-web (TypeScript)      contract tests run the real client against Pact's mock server
      │  pact file (6 interactions)
      ▼
Pact Broker (Docker)           contracts, verification results, branches, environments, deployments
      │                        can-i-deploy?  record-deployment
      ▼
product-service (Spring Boot)  JUnit 5 verification of the real app: provider states, token filter

Technology and tools

AreaTools
ConsumerTypeScript, fetch, Pact JS 17 (Pact specification V4), Vitest
ProviderJava 17, Spring Boot 4.1, Pact JVM 4.7 with JUnit 5, Maven wrapper
BrokerSelf-hosted Pact Broker 2.121 with PostgreSQL 17 in Docker Compose
Deployment checkspact-broker CLI: publish, can-i-deploy, create-environment, record-deployment
CIGitHub Actions: consumer and provider jobs, then the full broker workflow with the matrix on the run page

Engineering decisions and approach

  • The consumer's contract tests run its real HTTP client, so the contract records what the code really sends
  • Only the fields the consumer uses are in the contract, with type and format matchers; the provider may change the rest
  • Provider states with parameters ("a product exists" with id, price and stock) instead of one state per example
  • The contract accepts any Bearer token; the provider's request filter injects a valid one, but leaves the no-token case alone
  • Pending and WIP pacts: a consumer's new expectation never breaks the provider's build; can-i-deploy blocks the consumer instead
  • The breaking-change demo checks why can-i-deploy said no, so a no for another reason cannot pass as success

Test scope and execution approach

Project-specific checks and execution details documented in the repository:

  • 6 interactions: one product, 404, products by ids, reservation 201, 409 with the available stock, 401 without a token
  • Provider verification from the pacts folder (local) or the broker (CI), chosen by one environment variable
  • npm run contract: broker, consumer tests, publish, provider verification with results, can-i-deploy and record-deployment in about 35 seconds
  • npm run demo:breaking: a consumer feature branch expects a field the provider lacks; the provider stays green, the consumer is blocked
  • Mutation checks: renaming a field in the provider fails verification with the missing key named
  • Framework design notes and 76 interview questions on contract testing and Pact, linked to the code (Markdown + PDF)

Results with dated evidence

Historical repository or workflow evidence · older evidence; recheck the linked source

Contract workflow and README evidence

A TypeScript consumer and a Java Spring Boot provider, 6 interactions verified through a self-hosted Pact Broker; can-i-deploy blocks a breaking consumer change while the provider build stays green.

Evidence checked: | Open dated evidence

Evidence explorer

Static screenshots are labelled as images; dated workflow links identify the execution evidence and its check date.

Test report screenshot. The broker's matrix: the main version verified and deployed to production, the feature-branch version failed. Static image; capture date is not recorded in the portfolio data.
Pact Broker matrix with a verified main version and a failed feature-branch version

Test report screenshot. The broker's matrix: the main version verified and deployed to production, the feature-branch version failed. Static image; capture date is not recorded in the portfolio data.

Test report screenshot. can-i-deploy: yes for the main version, no for the feature version, with the reason. Static image; capture date is not recorded in the portfolio data.
can-i-deploy output: yes for the main version, no for the feature branch

Test report screenshot. can-i-deploy: yes for the main version, no for the feature version, with the reason. Static image; capture date is not recorded in the portfolio data.

Static material from the public repository. The linked verification record was checked 2026-10-16; that date is not a screenshot capture date.

Dated workflow record

Evidence checked 2026-10-16. Open Contract workflow and README evidence

Local setup and execution

npm ci && npm ci --prefix checkout-web
npm run contract        # the whole workflow (needs Docker and Java 17+)
npm run demo:breaking   # a breaking consumer change, blocked by can-i-deploy
npm run broker:down

Workflow and reports

View workflow definition.

Known limitations

  • One consumer; message (event) contracts are not included yet
  • The broker in CI is new for every run and has no authentication (a shared broker needs both)
  • The evidence is limited to the public repository and linked run; it does not establish customer production impact.

Back to Projects