Contract Testing with Pact

Hello everyone! :slight_smile:

Test-automation is quite new around here, and we have both “edges” covered by now: Unit Tests and E2E Tests (Web-automation using Playwright).

We would like to introduce other layers of testing, and where it currently hurts is integration between two services. Mostly, service A - would change Endpoint/field/parsing of a value and will break the contract with service B.

Enter contract-testing.

Pact seems to be a popular choice (I would love to hear about other popular options if any to check). Using pack seems to have a little bit of an overhead to it. Mainly, the fact that Service B, will have to supply a “Given” state so Service A tests can run (and that require great skills of communication and time to help between teams). Also, Pack-Broker seems to introduce some complexity.

There’s couple of other options in marked, that focus more on the producer side. Generate OpenAPI schema, and then there’s multiple tools that create diffs between versions (your branch and Mastet for example) to tell if API is broken. Protobuf also help with some of those issues as you use Object-Stubs. Pact main plus is probably being able to verify the VALUE of fields are still correct (in case you parse a specific prefix for example).

I wonder if you have any good/bad opinions about Pact, Pitfalls we should be aware of, alternative and if this has worked for you.

Thanks!

Pact is a great choice.

Checkout Pactflow for a hosted broker which takes away lots of the overhead.

Also checkout Pact slack (How to ask for help on Slack | Pact Docs) which can answer any specific questions.

State setup is definitely the biggest challenge when it comes to contract testing but there are lots of good examples in pact repositories.

Also if you have playwright tests already you can checkout the adaptor GitHub - pactflow/example-bi-directional-consumer-playwright-js: Bi-Directional Contract Testing example consumer using a BYO testing tool (Playwright) to generate Pact consumer contracts

Let me know if you have any other questions

1 Like

Hi there!

In my personal experience, contract testing with Pact has always worked very efficiently. Initially, teams may be hesitant to adopt it due to the required upfront work, but once they experience it, the value it provides is so significant that they usually end up being very satisfied with the outcome.
In my humble opinion, one of the greatest advantages of using a tool like Pactflow (or contract testing itself) is its automation capabilities and seamless integration into pipelines. However, as you mentioned, it may come with some overhead and complexity.

If you’re curious about the challenges you might face when trying to implement this framework, I recommend checking out our article series on contract testing, which covers multiple situations you might encounter when onboarding a large organization: Road to Pactflow Enterprise.

Additionally, here are three more articles focused on explaining the framework itself: Improve Microservice Testing with Contract Testing

Please feel free to reach out with any other questions or concerns you may have. Good luck with your contract testing journey! :slight_smile:

2 Likes

I shared this on Twitter. Here is another reply.

2 Likes

Hello everyone! Sorry for the super-late reply. I had to take some-time of work for a while.

Checkout Pactflow for a hosted broker which takes away lots of the overhead.

Yea, I think that if we will find Pact useful, hosted Broker is probably the way to go.

Also if you have playwright tests already you can checkout the adaptor GitHub - pactflow/example-bi-directional-consumer-playwright-js: Bi-Directional Contract Testing example consumer using a BYO testing tool (Playwright) to generate Pact consumer contracts

Will check it out, thanks!

In my humble opinion, one of the greatest advantages of using a tool like Pactflow (or contract testing itself) is its automation capabilities and seamless integration into pipelines

What do you mean by “automation capabilities”? It doesn’t integrate into the pipeline so easily right? because it require you to now work with Pact files/broker or block your CI because other teams tests etc?

Please feel free to reach out with any other questions or concerns you may have. Good luck with your contract testing journey! :slight_smile:

Thank you sharing the articles, I will be checking them today :slight_smile:

I shared this on Twitter. Here is another reply.

Thank you, will check it out!

1 Like