SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Get with the Pact - Gotchas of Implementing Contract Testing the right way
I gave this workshop at the European Testing Conference 2020 (https://europeantestingconference.eu/2020/).
The aim was to get to know some of the fundamentals of Pact more in-depth, and making sure we really get them right before we move on to scale this approach.
I gave this workshop at the European Testing Conference 2020 (https://europeantestingconference.eu/2020/).
The aim was to get to know some of the fundamentals of Pact more in-depth, and making sure we really get them right before we move on to scale this approach.
Get with the Pact - Gotchas of Implementing Contract Testing the right way
1.
GET/
with the Pact
Gotchas of
implementing
Contract Testing
the “right” way
2.
Bernardo Guerreiro
Senior Engineer @ Auth0
Platform Team
London, UK (Remote) 2
Twitter: @bernardobridge
Medium: https://medium.com/@bernardobridge
3.
Workshop Requirements
Do I need to know about Pact
already?
Nope. But it can’t hurt!
Do I need a laptop?
No. But you can follow with one!
3
Do I need to know Javascript?
No. But it would help to understand
some of the nuances. All concepts
are transferable.
@bernardobridge
4.
A Commit Story - The
Movie
https://github.com/bernardobridge/cinema-services-app/
4
@bernardobridge
10.
Key Takeaways
▹ You need testability before you need
Pact
▹ Work with developers to achieve that
▹ Mocking dependencies introduces a time
related risk - you never know what’s still
valid
▹ Integration Testing of Microservices can
get very complicated very fast
10
@bernardobridge
11.
Part 3
The Dark Pact
Contract Testing: a hero without a cape
@bernardobridge
13.
Key Takeaways
▹ Pact works very similarly to existing
mocking, but you are able to verify validity
of the contract over time
▹ Your contracts should be as narrow as
what your service actually consumes
▹ You can use Matchers to ensure your
contracts are well suited
▹ Provider state allows you to inject data
you may need to use to be able to replicate
calls when verifying the provider
▹ Having consistent naming conventions is
important to this workflow
13
@bernardobridge
14.
Part 4
V for Version
My version is better than your version :P
@bernardobridge
16.
Key Takeaways
▹ Pact pre-verifies versions for you when it
knows the contract hasn’t changed and it
had already been successfully verified
▹ Your provider version can’t just change
when you release, as that’s too late in the
release cycle
▹ You need your provider version to
dynamically change with new code
commits, so you can use commit sha’s
▹ Application Versions in the Pact world are
about what code is running
16
@bernardobridge
17.
Part 5
The Instagram Principle
Click here to tag your location
@bernardobridge
19.
Key Takeaways
▹ If versions are about what piece of code is
running, tags are about where it is running
▹ Branches are a natural candidate for
where the code is running
▹ You can use consumerVersionTags to
filter your provider verification results
▹ Think about the verification step triggered
by the consumer, and the verification step
from normal CI flow as different entities
▹ Make sure you are tagging the latest
master Pact with a prod tag after
releasing to prod. This lets you guarantee
backwards compatibility
19
@bernardobridge
20.
Final Thoughts
(you must be tired by now)
@bernardobridge
21.
Getting Started: a few tips
Run POC’s
Proofs of Concept
help establish
confidence in the
time/resource
investment by
demonstrating
usefulness with
minimal investment.
Involve Tech Leads
and Principals
These people have a
wide reach in the
organization, and can
help enforce/nail
down implementation,
proliferation and
technical decisions.
Involve SRE/DevOps
A lot of the hurdles
you will face will be
about retrofitting this
into a CI/CD pipeline.
Get help from the
experts in this area.
You’ll need it!
21
Become a Champion
Be the Champion for
adoption of this tool,
running workshops,
brown bags, POC’s
with teams, etc.
Create
RFC’s/equivalent
RFC (Request for
Comments) are a good
way to centralise
knowledge, clear
doubts, but also to
enforce conventions
everyone can adopt.
Get business buy-in
This is not easy, but if
business/product can
understand the value of
this, resource allocation
and help become much
easier to obtain. Pact
works best if everyone
uses it. It should be a
company goal.
@bernardobridge
22.
Useful Links
PACT.io Docs:
https://docs.pact.io/
Workshop Github Repo:
https://github.com/bernardobridge/cinema-services-app
Pact Foundation Slack Channel:
https://slack.pact.io/
UK Gov Lessons Learnt using Contract Testing:
https://technology.blog.gov.uk/2019/01/29/lessons-learnt-using-contract-testing-in-gov-
uk-pay/
Article I wrote about Authentication in Contract Testing:
https://medium.com/dazn-tech/pact-contract-testing-dealing-with-authentication-on-
the-provider-51fd46fdaa78
Installing your Pact Broker on Heroku (outdated version, delete the Gemfile.lock to install
more recent one):
https://github.com/YOU54F/pact-broker-heroku
Atlassian Swagger/Pact Validator:
https://bitbucket.org/atlassian/swagger-mock-validator/src/master/
22
23.
THANKS!
Any questions, please
reach out! I’m happy to
help.
You can find me at:
@bernardobridge
https://medium.com/@bernardobridge
23