Pact is a family of frameworks that support various languages and offer an easy way to set up Consumer Driven Contract Testing (more on this later). Their website can be found here, which provides comprehensive documentation if you prefer a different writing style.
Let's break it down:
A consumer is typically a web app or anything that consumes the provider, which can also be another API.
Usually, a provider refers to an API.
A contract is a file created by a test to expect a specific content type and body that should be sent to the consumer. For example, if you have a button on a form, clicking it may require passing a body and receiving a "complete" message in response.
First, we create a test on the consumer side, which generates our contract file. This contract should then be passed to the team handling the provider.
Manually sending contracts to the provider team would be a pain, but that's where a Pact Broker like PactFlow comes in. A Pact Broker easily integrates with your CI/CD system, and other teams can access contracts published on successful builds if desired.
With some CI/CD setup, you can ensure that providers must satisfy the contracts to deploy, eliminating the chance of broken builds for all consumers.
For setting up Pact, I recommend the following resources:
- Pact Repo: This repo provides several helpful examples of writing Consumer Driven Contract testing.
- React Pact Consumer Contract Example: React developers can check out this repository to learn how to get up and running.
In summary, Pact is a family of frameworks that enable Consumer Driven Contract Testing. The process involves creating contracts on the consumer side and somehow passing them to the provider for validation. By using Pact, you can ensure reliable and smooth interactions between consumers and providers.
Feel free to reach out if you have any questions or thoughts. Happy coding!