Contract Testing
An Introduction
What are they?
A suite of tests that allow you to “work with mocks that represent the
agreed-upon API contract between the services, but also, the
services (or teams really) that provide the API for consumption have
to uphold that API contract that is used in those mocks, and the
contract is enforced in their CI so they can’t break the API and go to
production.”
https://bit.ly/36Y6jMe
Why use Contract Tests?
• Work with mocks
• Be sure that the mocks represent the production API
• Help with resiliency when deploying to production
• Help ensure changes to APIs do not break in production
• Provide early warning to possible breaks
• Provide documentation for an API
• Provide mutually understandable code
https://bit.ly/36Y6jMe
Code Example (Java)
Fakes
• Developed locally by the Consumer team
• Represent a minimum viable implementation of the production
Provider
• Allow the tests against the Consumer to run locally
• Provide certainty that the code will work in production
• Can be easily integrated into a continuous integration pipeline
ProviderConsumer
Fake
Provider
Using Fakes
Service
Test
Contract
Test
Thanks

Contract Testing: An Introduction

  • 1.
  • 2.
    What are they? Asuite of tests that allow you to “work with mocks that represent the agreed-upon API contract between the services, but also, the services (or teams really) that provide the API for consumption have to uphold that API contract that is used in those mocks, and the contract is enforced in their CI so they can’t break the API and go to production.” https://bit.ly/36Y6jMe
  • 3.
    Why use ContractTests? • Work with mocks • Be sure that the mocks represent the production API • Help with resiliency when deploying to production • Help ensure changes to APIs do not break in production • Provide early warning to possible breaks • Provide documentation for an API • Provide mutually understandable code
  • 4.
  • 5.
  • 6.
    Fakes • Developed locallyby the Consumer team • Represent a minimum viable implementation of the production Provider • Allow the tests against the Consumer to run locally • Provide certainty that the code will work in production • Can be easily integrated into a continuous integration pipeline
  • 7.
  • 8.