Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Contract Testing with Pact

Contract Testing with Pact

David Tanzer

November 30, 2022
Tweet

More Decks by David Tanzer

Other Decks in Programming

Transcript

  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/