Contract Testing 101

Marie Drake

Quality Engineering Manager, Zoopla

@mcruzdrake | mariedrake.com

A Simple Service

@mcruzdrake

@mcruzdrake

@mcruzdrake

Unit Testing

  • Do not give us the confidence to release
  • Mock provider might not be the true representation of the real provider
  • Broken changes can be deployed

@mcruzdrake

Integration Testing

  • Becomes complex in microservices
  • Slow and brittle
  • Requires dedicated environments where services are integrated with one another
  • Lots of maintenance required
  • Broken changes can be deployed

@mcruzdrake

"How do you test a fire alarm?"

@mcruzdrake

Contract Testing?

A form of testing where you test the contract between the services communicating to each other.

 



 

  • Consumer
  • Provider
  • Pact/Contract
  • Pact Broker

@mcruzdrake

Pact https://pact.io/

A consumer driven contract testing tool

Pact tests the integration points that are actually use by the consumer(s).

@mcruzdrake

How does it work? (Consumer)

@mcruzdrake

How does it work? (Provider)

@mcruzdrake

Benefits of Contract Testing

  • Fast feedback
  • Run independently 
  • Less maintenance required
  • Gives us confidence to release
  • Doesn't need integrated environments to check the contract
  • Contract acts as a source of truth (additional documentation)
  • Evolve codebases continuously knowing that Pact will ensure contracts are satisfied.
  • Stop over reliance to slow integration or UI tests
  • Ensures that only parts of the API that will actually be used will be developed

@mcruzdrake

When not to use Pact or Contract Testing?

  • If there are no buy-ins from teams
  • Public APIs where you don't know who your consumers are
  • Third Party APIs

And remember...

 

  • Not a replacement for functional testing
  • Not a replacement for performance testing

@mcruzdrake

Contract Testing 101

By Marie Cruz

Contract Testing 101

  • 1,919