/Notes/ Consumer-Driven Contract Testing

Research into pact.io

  • Consumer-Driven Contracts (CDCs) are about the service-oriented relationship between services.
  • Consumers drive what the provider’s service level and interface is
    • Each consumer defines what it expects the provider to deliver and the provider has to do the checking.
    • Flow:
      1. Provider advertises an initial offer
      2. Consumer declares new expectations
      3. Provider ensures consumer expectations are met
      4. Integration occurs
  • How does it work?
    1. Developer of consumer service writes a test
      • Test defines an interaction with a provider
      • Includes state provider should be in, body of the request and the expected response
    2. Based on the definition of the consumer test, Pact creates and spins up a provider stub against which the test executes
      • Output of this test is one or more JSON files - these are the contracts (the pacts)
    3. Contracts are passed on to provider service
      • via shared repo, etc
    4. Provider tests if their service still ‘obeys’ the contract set by the consumer
      • Provider runs its own verification tests against a real-life version of its service, using shared pact file
    5. If tests do not succeed, provider developers should notify consumer developers

Baeldung Resource

CodeFresh Resource

Written on February 24, 2020