The rise of micro-service architectures offers the promise of a more agile software development process.
Software systems will be made up of many collaborating components which are developed, deployed and operated by distributed teams and organizations. But how can we avoid a recurring configuration nightmare (c.f. DLL hell) and ensure that we benefit from the promised flexibility, rather than creating a fragile, distributed monolith?
Contract testing offers an excellent solution.
Participants will be able to:
- Explain why contract testing is critically important
- Describe how to incorporate contract testing in your development practices
- Show their team where they can get an introduction to the open source tool, Pact.
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Software contracts and microservices
1. Software contracts
- agility in the world of micro-services
Seb Rose
Mastodon: @sebrose@mastodon.scot
Twitter: @sebrose
Blog: https://cucumber.io/blog/
E-mail: seb.rose@smartbear.com
Please help us by completing this 30 second
microservices and contract testing questionnaire.
3. @sebrose h
tt
p:/
/smartbear.com
Micro-service architecture …
… a collec
ti
on of services that are:
•Independently deployable
•Loosely coupled
•Organised around business capabili
ti
es
•Owned by a small team
•Highly maintainable and testable
h
tt
ps:/
/microservices.io/
4. @sebrose h
tt
p:/
/smartbear.com
Bene
fi
ts
The micro-service architecture enables the
rapid, frequent and reliable delivery of
large, complex applica
ti
ons. It also enables
an organiza
ti
on to evolve its technology
stack.
h
tt
ps:/
/microservices.io/
5. @sebrose h
tt
p:/
/smartbear.com
Pi
tf
alls
• The micro-service I depend on isn’t ready
• The micro-service I depend on doesn’t
provide the func
ti
onality I need
• I’m not con
fi
dent that the new version of
the micro-service will behave the same
• We want to update our micro-service, but
don’t know who is using it. Or how.
6. @sebrose h
tt
p:/
/smartbear.com
You have a distributed monolith
Beth Skurrie
If you can’t deploy services independently,
you don’t have micro-services.
Spot the he
ff
alump
7. @sebrose h
tt
p:/
/smartbear.com
TL;DR
• All interac
ti
ons between so
ft
ware
components are governed by contracts
• Contract tes
ti
ng ensures that both
components have the same expecta
ti
ons
• Contract tests should be wri
tt
en by the
developers
11. @sebrose h
tt
p:/
/smartbear.com
Design by contract
Design by contract
Contract
• an agreement between client
and supplier
Characteris
ti
cs
• expect some bene
fi
ts
• incur some obliga
ti
ons
16. @sebrose h
tt
p:/
/smartbear.com
▪Closed and complete Provider contracts express a service's business
function capabilities in terms of the complete set of exportable elements
available to consumers, and as such are closed and complete with respect
to the functionality available to the system.
▪Singular and authoritative Provider contracts are singular and authoritative
in their expression of the business functionality available to the system.
▪Bounded stability and immutability A provider contract is stable and
immutable for a bounded period and/or locale. Provider contracts typically
use some form of versioning to differentiate differently bounded instances
of the contract.
https://martinfowler.com/articles/consumerDrivenContracts.html
Provider contracts
17. @sebrose h
tt
p:/
/smartbear.com
▪Open and incomplete Consumer contracts are open and incomplete with
respect to the business functionality available to the system. They express
a subset of the system's business function capabilities in terms of the
consumer's expectations of the provider contract.
▪Multiple and non-authoritative Consumer contracts are multiple in
proportion to the number of consumers of a service, and each is non-
authoritative with regard to the total set of contractual obligations placed on
the provider. Consumers may evolve at different rates.
▪Bounded stability and immutability Like provider contracts, consumer
contracts are valid for a particular period of time and/or location.
https://martinfowler.com/articles/consumerDrivenContracts.html
Consumer driven contracts (CDC)
24. @sebrose h
tt
p:/
/smartbear.com
• Each consumer captures their expecta
ti
ons
of the provider in a separate contract.
• All of these contracts are shared with the
provider so they gain insight into the
obliga
ti
ons they must ful
fi
l for each
individual client.
• The provider can create a test suite to
validate these obliga
ti
ons.
h
tt
ps:/
/thoughtworks.github.io/pacto/pa
tt
erns/cdc/
Consumer driven contracts
31. @sebrose h
tt
p:/
/smartbear.com
JB Rainsberger, via GOOS mailing list, “Unit-test mock/stub assumptions rots”
15 March 2012
Systema
ti
c contract tes
ti
ng
• Collabora
ti
on tests make
assump
ti
ons about the contract
• Contract tests try to jus
ti
fy those
assump
ti
ons
JB Rainsberger, via GOOS mailing list, “Unit-test mock/stub assumptions rots”
15 March 2012
37. @sebrose h
tt
p:/
/smartbear.com
Pact provides a mechanism for crea
ti
ng a
contract between a service consumer and a
service provider, and then providing the tools
to validate that the consumer and provider
adhere to the contact independently of each
other.
https://dius.com.au/2014/05/19/simplifying-micro-service-testing-with-pacts/
Simplifying consumer driven contracts
38. @sebrose h
tt
p:/
/smartbear.com
•Consumer creates contracts using Pact DSL
•When consumer tests are run:
•Pact creates a mock HTTP server
•a Pact
fi
le is created
•Provider uses Pact
fi
le to verify compa
ti
bility
•Provider may o
ff
er “backdoor” interface
Pact - key points
43. @sebrose h
tt
p:/
/smartbear.com
• Pacts are published by Consumer
• Pacts are fetched by Provider
• Results are stored in the “Matrix”
• “Matrix” supports independent deployment
Pact broker - key points
44. @sebrose h
tt
p:/
/smartbear.com
Pact
fl
ow is the complete contract testing solution
allowing teams to orchestrate and scale their contract
testing initiative.
Visibility to focus on what ma
tt
ers
With Pact
fl
ow, developers can
fi
nd and
fi
x integration
errors earlier in the SDLC and teams can improve
communication & collaboration, reduce reliance on
E2E tests resulting in faster and safer deployments.
45. @sebrose h
tt
p:/
/smartbear.com
•Increases agility and con
fi
dence
•Reduces need for integra
ti
on tests
•Speeds up development
•No subs
ti
tute for communica
ti
on
•Is a development ac
ti
vity
•Does not replace other forms of tes
ti
ng
Take aways
Contract tes
ti
ng:
46. https://bddbooks.com
Please help us by completing this
30 second microservices and
contract testing questionnaire.
Seb Rose
Mastodon: @sebrose@mastodon.scot
Twitter: @sebrose
Blog: https://cucumber.io/blog/
E-mail: seb.rose@smartbear.com
Download these
slides