How does Pact work?
- In the tests for the provider facing code in the consumer project, expectations are set up on a mock service provider.
- When the tests are run, the mock service returns the expected responses. The requests, and their expected responses, are then written to a “pact” file.
- The requests in the pact file are later replayed against the provider, and the actual responses are checked to make sure they match the expected responses.
It is important to understand that Pacts are not schemas. A schema describes every possible valid combination of a document in one artifact. Pact operates on the principle of "contract by example". Each request/response pair only validates one of the possible states of the request/response.