PageSourceSearch

https://docs-pactflow-preview.netlify.app/assets/js/ffb80c65.7f138ff7.js

js docs-pactflow-preview.netlify.app collected 2026-10-03 10:40:24 UTC 11,031 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkpartners=self.webpackChunkpartners||[]).push([[7401],{15680:(e,t,n)=>{n.d(t,{xA:()=>l,yg:()=>y});var o=n(96540);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e,t){if(null==e)return{};var n,o,i=function(e,t){if(null==e)return{};var n,o,i={},r=Object.keys(e);for(o=0;o<r.length;o++)n=r[o],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(o=0;o<r.length;o++)n=r[o],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var c=o.createContext({}),p=function(e){var t=o.useContext(c),n=t;return e&&(n="function"==typeof e?e(t):a(a({},t),e)),n},l=function(e){var t=p(e.components);return o.createElement(c.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return o.createElement(o.Fragment,{},t)}},m=o.forwardRef((function(e,t){var n=e.components,i=e.mdxType,r=e.originalType,c=e.parentName,l=s(e,["components","mdxType","originalType","parentName"]),u=p(n),m=i,y=u["".concat(c,".").concat(m)]||u[m]||d[m]||r;return n?o.createElement(y,a(a({ref:t},l),{},{components:n})):o.createElement(y,a({ref:t},l))}));function y(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var r=n.length,a=new Array(r);a[0]=m;var s={};for(var c in t)hasOwnProperty.call(t,c)&&(s[c]=t[c]);s.originalType=e,s[u]="string"==typeof e?e:i,a[1]=s;for(var p=2;p<r;p++)a[p]=n[p];return o.createElement.apply(null,a)}return o.createElement.apply(null,n)}m.displayName="MDXCreateElement"},61527:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>d,frontMatter:()=>r,metadata:()=>s,toc:()=>p});var o=n(58168),i=(n(96540),n(15680));const r={title:"Consumer Testing Guide",sidebar_label:"Consumer"},a=void 0,s={unversionedId:"docs/bi-directional-contract-testing/consumer",id:"docs/bi-directional-contract-testing/consumer",title:"Consumer Testing Guide",description:"Principles",source:"@site/docs/docs/bi-directional-contract-testing/consumer.md",sourceDirName:"docs/bi-directional-contract-testing",slug:"/docs/bi-directional-contract-testing/consumer",permalink:"/docs/bi-directional-contract-testing/consumer",draft:!1,editUrl:"https://github.com/pactflow/docs.pactflow.io/edit/master/website/docs/docs/bi-directional-contract-testing/consumer.md",tags:[],version:"current",lastUpdatedBy:"Anubhuti Shrivastava",lastUpdatedAt:1689729397,formattedLastUpdatedAt:"Jul 19, 2023",frontMatter:{title:"Consumer Testing Guide",sidebar_label:"Consumer"},sidebar:"docs",previous:{title:"Overview",permalink:"/docs/bi-directional-contract-testing"},next:{title:"Provider",permalink:"/docs/bi-directional-contract-testing/provider"}},c={},p=[{value:"Principles",id:"principles",level:2},{value:"Writing Consumer Contracts",id:"writing-consumer-contracts",level:2},{value:"Prerequisite: choose a mocking tool",id:"prerequisite-choose-a-mocking-tool",level:3},{value:"Step 1: Write your consumer tests",id:"step-1-write-your-consumer-tests",level:3},{value:"Step 2: Convert your mocks (writing the pact adapter)",id:"step-2-convert-your-mocks-writing-the-pact-adapter",level:3},{value:"Step 3: Publish your contract",id:"step-3-publish-your-contract",level:3},{value:"Step 4: Run can-i-deploy",id:"step-4-run-can-i-deploy",level:3},{value:"Step 5: Deploy your application",id:"step-5-deploy-your-application",level:3},{value:"Integrating it into your CI/CD pipeline",id:"integrating-it-into-your-cicd-pipeline",level:2},{value:"Community Adapters",id:"community-adapters",level:2}],l={toc:p},u="wrapper";
1function d(e){let{components:t,...r}=e;return(0,i.yg)(u,(0,o.A)({},l,r,{components:t,mdxType:"MDXLayout"}),(0,i.yg)("h2",{id:"principles"},"Principles"),(0,i.yg)("p",null,"It is important for you to use a ",(0,i.yg)("em",{parentName:"p"},"mock")," and not a ",(0,i.yg)("em",{parentName:"p"},"stub"),". The crucial difference is that a mock validates behaviour, whereas a stub does not. We need to ensure that your consumer code calls the mock, otherwise we will serialise a contract with invalid expectations."),(0,i.yg)("h2",{id:"writing-consumer-contracts"},"Writing Consumer Contracts"),(0,i.yg)("p",null,(0,i.yg)("img",{alt:"Consumer Test",src:n(62305).A,title:"Consumer Test",width:"2560",height:"1440"})),(0,i.yg)("h3",{id:"prerequisite-choose-a-mocking-tool"},"Prerequisite: choose a mocking tool"),(0,i.yg)("p",null,"If you're not using Pact, you need to pick a tool that can extract the mocking information from or use a pre-existing ",(0,i.yg)("a",{parentName:"p",href:"#community-adapters"},"adapter"),", to convert it to a pact file."),(0,i.yg)("p",null,"Some tools have options to serialise mocks to files, and others will require you to introspect via their APIs. You should consider this in advance."),(0,i.yg)("h3",{id:"step-1-write-your-consumer-tests"},"Step 1: Write your consumer tests"),(0,i.yg)("p",null,"Once you have chosen your tool, you must implement consumer side tests. It is important that you exercise all the API behaviour your system expects to ensure you have optimal coverage."),(0,i.yg)("p",null,"One notably deviation from Pact advice is that you need not concern yourself with finding the minimal set of tests for a contract and are free to use mocks for any functional testing. In fact, this is encouraged."),(0,i.yg)("p",null,"(Reference to standard contract testing advice: ",(0,i.yg)("a",{parentName:"p",href:"https://docs.pact.io/consumer/contract_tests_not_functional_tests/"},"https://docs.pact.io/consumer/contract_tests_not_functional_tests/"),")"),(0,i.yg)("h3",{id:"step-2-convert-your-mocks-writing-the-pact-adapter"},"Step 2: Convert your mocks (writing the pact adapter)"),(0,i.yg)("p",null,(0,i.yg)("em",{parentName:"p"},"NOTE: If you chose Pact in Step 1, you could skip to Step 3.")),(0,i.yg)("p",null,"Read the ",(0,i.yg)("a",{parentName:"p",href:"./contracts/pact"},"documentation")," on how to generate a pact contract from your mocks."),(0,i.yg)("admonition",{type:"info"},(0,i.yg)("p",{parentName:"admonition"},"We will be building adapters for common mocking tools as we expand this feature. See current ",(0,i.yg)("a",{parentName:"p",href:"#community-adapters"},"community contributed adapters")," below.")),(0,i.yg)("h3",{id:"step-3-publish-your-contract"},"Step 3: Publish your contract"),(0,i.yg)("p",null,"Uploading a pact file is the same as the standard ",(0,i.yg)("a",{parentName:"p",href:"https://docs.pact.io/pact_broker/publishing_and_retrieving_pacts/"},"Pact process"),"."),(0,i.yg)("p",null,"We recommend using the ",(0,i.yg)("inlineCode",{parentName:"p"},"pact-broker publish")," command from ",(0,i.yg)("a",{parentName:"p",href:"https://docs.pact.io/implementation_guides/cli/#distributions"},"CLI Tools")," for this step. Our examples use the Docker version to simplify administration."),(0,i.yg)("p",null,(0,i.yg)("img",{alt:"Contract Upload",src:n(97124).A,title:"Contract Upload",width:"2560",height:"1440"})),(0,i.yg)("h3",{id:"step-4-run-can-i-deploy"},"Step 4: Run can-i-deploy"),(0,i.yg)("p",null,(0,i.yg)("a",{parentName:"p",href:"https://docs.pact.io/pact_broker/can_i_deploy/"},(0,i.yg)("inlineCode",{parentName:"a"},"can-i-deploy"))," gives you immediate feedback if you are safe to release a version of an application to a specified environment (such as ",(0,i.yg)("inlineCode",{parentName:"p"},"production"),")."),(0,i.yg)("p",null,"We recommend using the ",(0,i.yg)("inlineCode",{parentName:"p"},"pact-broker can-i-deploy")," command from ",(0,i.yg)("a",{parentName:"p",href:"https://docs.pact.io/implementation_guides/cli/#distributions"},"CLI Tools")," for this step. Our examples use the Docker version to simplify administration."),(0,i.yg)("p",null,"The command output will provide a link to the verification results in PactFlow. Interpreting these results is contract specific."),(0,i.yg)("p",null,"Here is our pipeline to date for the first run of a consumer:"),(0,i.yg)("p",null,(0,i.yg)("img",{alt:"Consumer Pipeline First Run",src:n(92934).A,title:"Consumer Pipeline First Run",width:"960",height:"540"})),(0,i.yg)("h3",{id:"step-5-deploy-your-application"},"Step 5: Deploy your application"),(0,i.yg)("p",null,"If ",(0,i.yg)("inlineCode",{parentName:"p"},"can-i-deploy")," returns a successful response, you can deploy your application. Once your application is deployed, you can notify PactFlow of the release - see the ","[recording deployments & releases]"," (",(0,i.yg)("a",{parentName:"p",href:"https://docs.pact.io/pact_broker/recording_deployments_and_releases"},"https://docs.pact.io/pact_broker/recording_deployments_and_releases"),") docs"),(0,i.yg)("p",null,(0,i.yg)("em",{parentName:"p"},"Golden rule:")),(0,i.yg)("blockquote",null,(0,i.yg)("p",{parentName:"blockquote"},"Associate with the branch name when publishing pacts or verification results and record the deployment or release into any environment.")),(0,i.yg)("h2",{id:"integrating-it-into-your-cicd-pipeline"},"Integrating it into your CI/CD pipeline"),(0,i.yg)("p",null,"A simplified view of a CI/CD pipeline for Pact looks like this:"),(0,i.yg)("p",null,(0,i.yg)("img",{alt:"Consumer Pipeline",src:n(80665).A,title:"Consumer Pipeline",width:"1833",he
1ight:"699"})),(0,i.yg)("p",null,"The standard ",(0,i.yg)("a",{parentName:"p",href:"https://docs.pact.io/pact_nirvana"},"principles")," are still relevant. Our ",(0,i.yg)("a",{parentName:"p",href:"/docs/workshops/ci-cd"},"CI/CD workshop")," is a useful reference (NOTE: the CI/CD workshop uses consumer-driven mode using Pact)."),(0,i.yg)("h2",{id:"community-adapters"},"Community Adapters"),(0,i.yg)("p",null,"All the official and community adapters and guides can be found at ",(0,i.yg)("a",{parentName:"p",href:"/docs/bi-directional-contract-testing/tools"},"tooling integration"),"."))}d.isMDXComponent=!0},62305:(e,t,n)=>{n.d(t,{A:()=>o});const o=n.p+"assets/images/1-bi-directional-consumer-testing-scope-cce3345100bf1a67a2e9352f43417222.png"},97124:(e,t,n)=>{n.d(t,{A:()=>o});const o=n.p+"assets/images/1-bi-directional-how_it_works_overview-a66612237bc4bdaf97608aa83f0d0e77.png"},92934:(e,t,n)=>{n.d(t,{A:()=>o});const o=n.p+"assets/images/2-bi-directional-consumer-pipeline-first-run-1c32471b3f07cd863af5222e5b0ac641.png"},80665:(e,t,n)=>{n.d(t,{A:()=>o});const o=n.p+"assets/images/3-bi-directional-consumer-pipeline-deployed-b37f85fff9187378da04bbf1e77c476e.png"}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.