Skip to content

khareyash05/pact-go

Repository files navigation

Contract testing

Contract testing is an essential technique for ensuring reliable communication between distributed systems. It involves testing the interactions between the components of a system by defining a set of agreed-upon contracts that specify the expected behavior of each component. This technique helps to catch any breaking changes that may occur during the development process, reducing the risk of system failure in production. 1_64wLFdRJG6xjxZhSsrsCCQ We in general generate integration tests for our applications to check whether microservices goes hand in hand.
Most famous integration testing is the e2e testing which test all microservices as whole as they will be when in production.

Problems with e2e integration testing

  1. Time Consuming
  2. Not easy to detect faults
  3. Not compatible with microservices changing demands as it might cause other microservices to break.
    Thus Contract Testing came into play

What is Pact?

  1. Pact is a popular contract testing tool that provides a framework for implementing contract testing in a variety of languages and frameworks, including Go
  2. Pact works by generating mock servers that simulate the behavior of a provider system, allowing the consumer system to test its interactions with the provider and generate a contract that specifies the expected behavior of the provider

Steps to perform Contract Testing

#1 Generate/update a contract:

  1. cd /pkg/client
  2. go test

#2 Run provider test to validate it against the contract:

  1. cd /pkg/server
  2. go test

Output

1_L_UfSS7tKnAxe5lo2cENZw
Testing and validating the contract

1_FajCLxCUA1fZEYyoP_s9zg

About

Contract Testing using Pact

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published