Contract Tests vs WireMock Stubs
Quick answer
Short answer: Stubs are a code-level description of the responses; contract tests verify the responses against the schema. The first tells the mock what to return; the second proves the real response is valid. They are different stages and both belong in a pipeline.
Short answer: Stubs are a code-level description of the responses; contract tests verify the responses against the schema. The first tells the mock what to return; the second proves the real response is valid. They are different stages and both belong in a pipeline.
What stubs provide
Controlled responses for the tests, so the system can be exercised without the real service. They are authored and can drift.
What contract tests provide
| Property | Stubs | Contract tests |
|---|---|---|
| Subject | Mock responses | Real responses |
| Authority | Stub code | Schema |
| Catches drift | Not directly | Yes |
| Stage | Isolation | Verification |
Why the stages matter
A stub lets the system run without the dependency; a contract test proves the dependency still conforms. Replacing one with the other leaves a gap.
The honest takeaway
Keep the stubs for isolation and the contract checks for conformance. A spec-first studio keeps both tied to the same source.
This is part of the Powerduck vs WireMock comparison. Next, read beyond JVM mocking.
Frequently asked questions
What does stub provide?
Controlled responses for the tests, so the system can be exercised without the real service. They are authored and can drift.
What is contract tests provide?
PropertyStubsContract tests SubjectMock responsesReal responses AuthorityStub codeSchema Catches driftNot directlyYes StageIsolationVerification
Why does the stage matter?
A stub lets the system run without the dependency; a contract test proves the dependency still conforms. Replacing one with the other leaves a gap.
What is the honest takeaway?
Keep the stubs for isolation and the contract checks for conformance. A spec-first studio keeps both tied to the same source. This is part of the Powerduck vs WireMock comparison. Next, read beyond JVM mocking.