Course contentsShow
← Software Engineering
Lesson 548 of 1,93316. Integration TestingFree lesson

What is Contract Testing

Understanding contract testing as a technique to verify interactions between services match agreed-upon contracts.

What is Contract Testing

You'll learn: what contract testing is and why it helps prevent integration failures between services.

The Core Idea

Contract testing is a testing technique that verifies two separate services can communicate correctly by checking that both sides of their interaction follow an agreed-upon "contract" — a specification of what requests and responses should look like.

Think of it like two puzzle pieces. Rather than waiting to see if they fit together (full integration testing), you test each piece individually against the shape they promised to have. If both pieces match their promised shapes, they'll fit together when assembled.

How It's Different from Integration Testing

Traditional integration testing connects real services together and tests them end-to-end. Contract testing instead verifies each side independently:

  • The consumer (the service making requests) tests: "Do I send requests in the format my provider expects?"
  • The provider (the service receiving requests) tests: "Do I return responses in the format my consumers expect?"

Both sides test against the same contract document, but separately.

Why Contract Testing Matters

When services are developed by different teams or change frequently, contract testing catches breaking changes early:

  • A provider team changes their API response format → their contract tests fail before deployment
  • A consumer team expects a new field → they create a contract test that alerts the provider team
  • No need to spin up both services just to verify compatibility

Key Takeaway: Contract testing verifies that services fulfill their interaction agreements independently, catching integration problems without requiring both services to run together during testing.