Skip to content
Skills Library
Programming · Testing

contract-testing

/contract-testing

Contract testing for API consumers and providers. Pact framework, Spring Cloud Contract, consumer-driven contracts, provider verification, and contract broker setup. USE WHEN: user mentions "contract testing", "Pact", "consumer-driven contract", "Spring Cloud Contract", "API contract", "provider verification" DO NOT USE FOR: OpenAPI validation - use `openapi-contract`; integration testing - use integration test skills

Licence
MIT
Last repository change
21.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
3
Deprecation

No signals detected. Repository changed on 21.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Contract testing for API consumers and providers. Pact framework, Spring Cloud Contract, consumer-driven contracts, provider verification, and contract broker setup. USE WHEN: user mentions "contract testing", "Pact", "consumer-driven contract", "Spring Cloud Contract", "API contract", "provider verification" DO NOT USE FOR: OpenAPI validation - use `openapi-contract`; integration testing - use integration test skills

Triggers from the description

contract testingPactconsumer-driven contractSpring Cloud ContractAPI contractprovider verification
Original author description

Contract testing for API consumers and providers. Pact framework, Spring Cloud Contract, consumer-driven contracts, provider verification, and contract broker setup. USE WHEN: user mentions "contract testing", "Pact", "consumer-driven contract", "Spring Cloud Contract", "API contract", "provider verification" DO NOT USE FOR: OpenAPI validation - use `openapi-contract`; integration testing - use integration test skills

How it works

  1. Pact (Consumer-Driven Contracts)
  2. Spring Cloud Contract
  3. Workflow
  4. Pact Broker
  5. Anti-Patterns
  6. Production Checklist
Original SKILL.md headings · 155 lines, 462 words
SKILL.md preview
---
name: contract-testing
description: |
  Contract testing for API consumers and providers. Pact framework,
  Spring Cloud Contract, consumer-driven contracts, provider verification,
  and contract broker setup.

  USE WHEN: user mentions "contract testing", "Pact", "consumer-driven contract",
  "Spring Cloud Contract", "API contract", "provider verification"

  DO NOT USE FOR: OpenAPI validation - use `openapi-contract`;
  integration testing - use integration test skills
allowed-tools: Read, Grep, Glob, Write, Edit
---
# Contract Testing

## Pact (Consumer-Driven Contracts)

### Consumer Test (Node.js)

```typescript
import { PactV3, MatchersV3 } from '@pact-foundation/pact';

const { like, eachLike, string, integer } = MatchersV3;

const provider = new PactV3({
  consumer: 'OrderService',
  provider: 'ProductService',
});

describe('Product API contract', () => {
  it('returns a product by ID', async () => {
    await provider
      .given('product 123 exists')
      .uponReceiving('a request for product 123')
      .withRequest({
        method: 'GET',
        path: '/api/products/123',
        headers: { Accept: 'application/json' },
      })
      .willRespondWith({
        status: 200,
        headers: { 'Content-Type': 'application/json' },
        body: like({
          id: string('123'),
          name: string('Widget'),
          price: integer(1999),
        }),
      })
      .executeTest(async (mockserver) => {
        const client = new ProductClient(mockserver.url);
        const product = await client.getProduct('123');
        expect(product.id).toBe('123');
        expect(product.name).toBeDefined();
      });
  });
});
```

### Provider Verification

```typescript
import { Verifier } from '@pact-foundation/pact';

describe('Product provider verification', () => {
  it('validates contracts', async () => {
    await new Verifier({
      providerBaseUrl: 'http://localhost:3000',
      pactUrls: ['./pacts/OrderService-ProductService.json'],
      // Or from broker:
      // pactBrokerUrl: 'https://pact-broker.example.com',
      // publishVerificationResult: true,
      // providerVersion: process.env.GIT_SHA,
      stateHandlers: {
        'product 123 exists': async () => {
          await db.product.create({ data: { id: '123', name: 'Widget', price: 1999 } });
        },
      },
    }).verifyProvider();
  });
});
```

## Spring Cloud Contract

### Contract Definition (Groovy DSL)

```groovy
// contracts/shouldReturnProduct.groovy
Contract.make {
    description "should return product by ID"
    request {
        method GET()
        url "/api/products/123"
        headers { contentType applicationJson() }
    }
    response {
        status OK()
        headers { contentType applicationJson() }
        body([
            id: "123",
            name: $(regex('[A-Za-z ]+')),
            price: $(regex('[0-9]+')),
        ])
    }
}
```

### Provider Base Test

```java
@SpringBootTest(webEnvironment = WebEnvironment.MOCK)
@AutoConfigureMockMvc
public abstract class ContractBaseTest {
    @Autowired MockMvc mockMvc;
    @MockBean ProductRepository productRepo;

    @BeforeEach
    void setup() {
        when(productRepo.findById("123"))
            .thenReturn(Optional.of(new Product("123", "Widget", 1999)));
        RestAssuredMockMvc.mockMvc(mockMvc);
    }
}
```

## Workflow

```
1. Consumer writes contract test → generates pact file
2. Pact file published to broker (or shared via file)
3. Provider runs verification against pact
4. Both sides deploy only when contracts pass
```

## Pact Broker

```bash
# Publish pact
npx pact-broker publish ./pacts \
  --consumer-app-version=$(git rev-parse HEAD) \
  --broker-base-url=https://pact-broker.example.com

# Can I Deploy?
npx pact-broker can-i-deploy \
  --pacticipant=OrderService \
  --version=$(git rev-parse HEAD) \
  --to-environment=production
```

## Anti-Patterns

| Anti-Pattern | Fix |
|--------------|-----|
| Testing implementation details | Test contract shape, not business logic |
| Over-specifying response fields | Use matchers (like, regex), not exact values |
| No state management | Define provider states for test data setup |
| Contracts not in CI | Run contract tests in CI/CD pipeline |
| Skipping provider verification | Both sides must run their tests |

## Production Checklist

- [ ] Consumer-driven contracts for all API dependencies
- [ ] Pact Broker (or equivalent) for contract sharing
- [ ] Provider verification in CI pipeline
- [ ] `can-i-deploy` check before deployment
- [ ] Provider states for test data setup
- [ ] Contract versioned with git SHA

Versions

RepositoryScoreLicence
This page · claude-dev-suite/claude-dev-suite100MIT
proffesor-for-testing/agentic-qe100MIT
sebastiendegodez/skraft-plugin100GPL-3.0
petrkindlmann/qa-skills100MIT
thedaviddias/front-end-checklist100MIT
jacob-balslev/skill-graph100Apache-2.0
Tyler-R-Kendrick/agent-skills95MIT
RobinBeraud/claude-qa-skills90MIT
Amey-Thakur/AI-SKILLS90MIT

Database snapshot: 13.11.2026 · package version 9caca6144b00 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90quality-contract-testing
    Use this skill when setting up contract testing, Pact, consumer-driven contracts, provider contract verification, API compatibility, or integration testing between services. This skill enforces: consumer-driven contracts with Pact, provider-side verification, contract publishing…
  • 100pact-contract-testing
    Authors and verifies Pact consumer-driven contract tests across the full Pact lifecycle - consumer tests producing pact files, publishing to the Pact Broker, provider verification, and `can-i-deploy` deployment gates. Use when introducing a new HTTP/JSON API contract between two…
  • 100validating-api-contracts
    Validate API contracts using consumer-driven contract testing (Pact, Spring Cloud Contract). Use when performing specialized testing. Trigger with phrases like "validate API contract", "run contract tests", or "check consumer contracts".
  • 100validating-api-contracts
    Validate API contracts using consumer-driven contract testing (Pact, Spring Cloud Contract). Use when performing specialized testing. Trigger with phrases like "validate API contract", "run contract tests", or "check consumer contracts".
  • 90mock-contract
    Design a consumer-driven contract testing setup — Pact configuration and CI integration. Use when asked to "set up contract testing", "configure Pact", or "add consumer-driven contracts".
  • 100pact-contract-testing-configuration
    Sets up consumer-driven contract testing with Pact — writing consumer contract tests that generate a pact file, standing up and configuring a Pact Broker (or PactFlow) to publish and share contracts, and writing provider verification tests against the broker's published pacts.…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.