Skip to content

Consumer-Driven Contract Testing between the microservices which are developed in different tech stacks.

Notifications You must be signed in to change notification settings

suadev/consumer-driven-contract-testing-microservices

Repository files navigation

Why?

E2E testing is one of the biggest challenges in distributed systems. Consumer-Driven Contract Testing is an excellent alternative to deal with this challenge.

This workshop shows how to implement Consumer-Driven Contract Testing between the microservices which are developed in different tech stacks.

Pact framework is used to create and verify contracts between the microservices.

There are 3 microservices that communicate syncronously each other.

Porovider Service -> Product Service (.Net5)

Consumer Service(1) -> Search Service (Go 1.16)

Consumer Service(2) -> Price Service (Go 1.16)

Run in Debug Mode

You need Pact Broker and Postgres container to play with the. workshop. First, run docker-compose up in the root path.

Then, Select 'All' Debug Configuration and start debugging. (for Vs Code users) All microservices will be running in debug mode.

You may want to play with the services before creating and verifying contracts. See sample postman requests here.

Creating Contracts

After running all services, you need to publish your consumer-driven contracts. Run contract tests for Search and Price services;

cd consumer-price-service/test
go test
cd consumer-search-service/test
go test

After running these tests successfully, you will see the unverified contracts on Pact Broker home page which is hosting on http://localhost:9292

And, you can also see the network graph between the services by clicking on any of them.

Verifying Contracts

You have 2 contracts that were published by 2 consumer services. To verify these contracts, just run the provider's contract test like below.

cd provider-product-service/test
dotnet test

If the test is passed, you will see verified contracts like below. Pay attention to the "Last Verified" column;

Next?

Try to break contracts between the services. Pact Broker shows the broken contracts with red background.

Following Pact list means;

'Product Service just made a change that breaks the contract with Price Service. Search service is not affected by this change.'

About

Consumer-Driven Contract Testing between the microservices which are developed in different tech stacks.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published