Contract Testing with Pact

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
David Tanzer
November 30, 2022

Contract Testing with Pact

David Tanzer

November 30, 2022

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

34 slides
  1. Today... Today... Today... Today... Today... Integration Testing Integration vs. Integrated

    Testing Testing Locally? -> Contract Testing Better Contract Testing with Pact Pact Broker Can I deploy? @[email protected] 4
  2. Integrated Integrated Integrated Integrated Integrated Pros Comprehensive "Smoke-Test" Cons Slow

    All parts must be running Hard to maintain Hard to pin failures Test Data Management Integration Integration Integration Integration Integration Pros Easier to maintain Test can run locally Usually faster Test data setup easier Cons No complete workflow Pros & Cons Pros & Cons Pros & Cons Pros & Cons Pros & Cons @[email protected] 13
  3. Advantages Advantages Advantages Advantages Advantages Both parts can be tested

    independently and locally Pact ensures consistency between tests @[email protected] 23
  4. Pact Broker Pact Broker Pact Broker Pact Broker Pact Broker

    Server Software Records versions of consumers and verified providers https://pactflow.io/ Or run docker image @[email protected] 25
  5. Usage Usage Usage Usage Usage 1. Consumer CI build Run

    Pact tests Publish Pact Triggers Provider Tests 2. Provider CI build Runs Pact verification If the pact verification fails, the build fails Can I deploy? Deploy 3. Back to the Consumer CI build Can I deploy? Deploy @[email protected] 26
  6. Can I Deploy? Can I Deploy? Can I Deploy? Can

    I Deploy? Can I Deploy? Consumer Provider Verified 22 56 true 23 56 true 23 57 false 23 58 true 24 58 true 25 58 false @[email protected] 27
  7. $ pact-broker record-deployment --pacticipant Bar --version 56 \ --environment production

    Consumer Provider Verified 22 56 (production) true 23 56 (production) true 23 57 false 23 58 true 24 58 true 25 58 false @[email protected] 28
  8. $ pact-broker can-i-deploy --pacticipant Foo --version 23 \ --to-environment production

    Computer says yes \o/ CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS? | RESULT# ---------|------------|----------|------------|----------|-------- Foo | 23 | Bar | 56 | true | 1 $ pact-broker can-i-deploy --pacticipant Foo --version 24 \ --to-environment production Computer says no ¯_(ツ)_/¯ CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS? | RESULT# ---------|------------|----------|------------|----------|-------- Foo | 24 | Bar | 56 | false | 1 @[email protected] 29
  9. Pact can help you find communication problems early You probably

    still need some integration tests (and even integrated tests) @[email protected] 31
  10. About David About David About David About David About David

    Trainer, Coach, Developer https://davidtanzer.net @[email protected] Slides: speakerdeck.com/dtanzer/

More Decks by David Tanzer

Other Decks in Programming