DEV Community

Luke Brannagan
Luke Brannagan

Posted on

Getting started with Pact and Consumer Driven Contract Testing

Table of Contents

What is Pact?

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.

What are Consumer Driven Contracts?

Let's break it down:

What's a consumer?

A consumer is typically a web app or anything that consumes the provider, which can also be another API.

What's a provider?

Usually, a provider refers to an API.

What's a contract (or pact)?

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.

How does the testing theory work?

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.

Setting Up

For setting up Pact, I recommend the following resources:

Summary

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!

Top comments (0)