SlideShare a Scribd company logo
Pact Tests
(Consumer Driven Contracts)
Based on a true (truly imaginary?) story!
Alice
• our main character in the story
• Senior Dev in FreshMock.com
• Owns a “Subscription Service”
• Friday the 13th!
What happened on Friday the 13th?
● “CustomerInfo Service”’s change
● Updates a property in the response object
● Changes “customer” (which returns a list of customers) to
“customers” (Grammatically correct though! :( )
● BUT this one letter change BROKE the “Subscription Service”
Here comes the bigger question…
Why didn't our tests
catch this??
So how do you test?
● Mock the dependencies
Subscription Service Mock CustomerInfo Service
Request
Response
Unit Tests
● Similarly the “CustomerInfo Service”, has a mock client for
“Subscription Service”
● It DID fail!
● But then “I updated my test because I know this is an expected
failure! ”
Unit Tests
● Why do we still do it?
• Fast
• Easy to setup
• No Flakiness!
• Ensures functionality of a specific microservice
Integration Tests
Subscription Service CustomerInfo Service
Request
Response
Integration Tests
● Slower
● Set up time (“Stack Setup!”)
● More flakiness
● More infrastructure!
● End up doing an E2E tests
Other types of Tests
•End-to-End Tests
•Manual Tests
•Again,
• Stack Setup!
• Slower (E2E tests)
• More flakiness
• Not failing fast!
Solution?
Is there a better way to identify
these kind of issues?
Pact Tests
• Also called “Contract Tests”
• Consumer Driven Contract Tests (CDC Tests)
• Tool Used: Pact
• A Contract is a collection of agreements between a client (Consumer)
and an API (Provider) that describes the interactions that can take
place between them.
Pact Tests? What are these?
Subscription Service CustomerInfo Service
Request
Response
Consumer Provider
Sends
response
for
assertions
Pact Tests: Consumer Side
Tests
Set
Expectations
Pact Mock Provider
Tests
invoke
code
Source Code
Sends
HTTP
Requests
Sends
expected
response
Is it just another Mock HTTP Server?
Subscription Service CustomerInfo Service
Request
Response
Consumer Provider
The Pact File
• Every HTTP Request and Response is
captured
• Standard way of representing
interactions - JSON file
• This is shared with the Provider.
• Explains everything that a consumer
expects from the Provider - the
endpoints, query params, header and
the response objects.
Pact Tests:Provider Side
CustomerInfo Service
Replay each HTTP Request
Get real HTTP Response
Provider
Pact File Compares real and
mock responses
Provider States
• Get billing address of customer
with id=777
Subscription Service CustomerInfo Service
Request
Response
Consumer Provider
Request
Response
?
state: cust_id=777 @ DB
Provider States
• Get billing address of customer
with id=777
Subscription Service CustomerInfo Service
Request
Response
Consumer Provider
Request
Response
state: cust_id=777 @ DB
state: cust_id=777 @ DB
Sharing Pact Files
Filesystem Cloud Pact BrokerCI Build
Artefact
Sharing Pact Files - Pact Broker
• Pact Broker - a repo for storing pacts
• Auto-generated documentation
• The ability to tag a Pact (i.e. “prod") -
versioning pacts
• Network Graph
Sharing Pact Files - Pact Broker
Automating Pact Tests
• When a new Pact is published, how does the Provider get notified?
Manual Trigger Pact Broker
Webhook
Swagger Validator
Advantages
•Eliminates Wrong Assumptions
•Enables communication
•Very less setup time!
•No extra infrastructure
•Fast in Execution
•Fails Fast
•No flakiness!
•Easy to debug
DEMO
Freshapps DevPortal Freshapps Activities
Request
Response
Consumer Provider
Consumer Side : Setup Mock Server
Pact.service_consumer 'DevPortal' do
end
Consumer Side : Setup Mock Server
Pact.service_consumer 'DevPortal' do
has_pact_with "Freshapps Activities" do
end
end
Consumer Side : Setup Mock Server
Pact.service_consumer 'DevPortal' do
has_pact_with "Freshapps Activities" do
mock_service :freshapps_activities do
port 3005
end
end
end
Consumer Side : Setup Expectations
freshapps_activities.given(“all activities without role param")
Consumer Side : Setup Expectations
freshapps_activities.given(“all activities without role param")
.upon_receiving("a request for all activities")
.with(
method: :get,
path: '/all/activities.json',
query: {
page: '1',
account_id: '1' },
headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'} )
Consumer Side : Setup Expectations
freshapps_activities.given(“all activities without role param")
.upon_receiving("a request for all activities")
.with(
method: :get,
path: '/all/activities.json',
query: {
page: '1',
account_id: '1' },
headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'} )
.will_respond_with(
status: 422,
headers: {
'Content-Type' => 'application/json; charset=utf-8' },
body: { "error_msg" => "Required parameter missing" } )
Consumer Side : Make Request & Assert
resp = FreshappsActivitiesClient.get_activities(path, query, header)
Consumer Side : Make Request & Assert
resp = FreshappsActivitiesClient.get_activities(path, query, header)
expected_response = { "error_msg" => "Required parameter missing" }
expect(resp.parsed_response.inspect).to eq(expected_response.inspect)
Generated Pact File
{
"consumer": {
"name": "DevPortal"
},
"provider": {
"name": "Freshapps Activities"
},
"interactions": [
{
"description": "a request for all activities",
"provider_state": "all activities without role param",
"request": {
"method": "get",
"path": "/all/activities.json",
"query": "page=1&account_id=1",
"headers": {
"Content-Type": "application/json",
"Accept": "application/json"
}
},
"response": {
"status": 422,
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"body": {
"error_msg": "Required parameter missing"
}
}
}
],
"metadata": {
"pactSpecificationVersion": "1.0.0"
}
}
Provider Side : Make Request & Assert
Pact.service_provider 'Freshapps Activities' do
end
Provider Side : Make Request & Assert
Pact.service_provider 'Freshapps Activities' do
honours_pact_with 'DevPortal' do
end
end
Provider Side : Make Request & Assert
Pact.service_provider 'Freshapps Activities' do
honours_pact_with 'DevPortal' do
pact_uri "../freshapps_devportal/spec/pacts/devportal-freshapps_activities.json"
end
end
end
Provider Side : Setup Test Data
Pact.provider_states_for "DevPortal" do
provider_state "all activities without role param" do
end
end
Remember:
Consumer Assumed:
freshapps_activities.given(“
all activities without role
param")
Provider Side : Setup Test Data
Pact.provider_states_for "DevPortal" do
provider_state "all activities without role param" do
set_up do
factory :activity do
account_id 1
user_id 1
extension_id 2
version_id 2
activity_type 'Extension'
visibility 1
activity { 'extension_id' => '2', 'name' => 'Sample Extension’}
end
end
end
end
Remember:
Consumer Assumed:
freshapps_activities.given(“
all activities without role
param")
Provider Side : Pact Verify Failure
Provider Side : Pact Verify Success
pact.io
• Working examples and documentations available at pact.io
• Supports: Ruby, Java, .NET
• Beta: JS,Python, Swift, Go
• https://groups.google.com/forum/#!forum/pact-support
• https://gitter.im/realestate-com-au/pact
• Other Similar Tools:
• Pacto (by Thoughtworks - but not maintained though.)
References
● To know about Consumer Driven Contract: https://
martinfowler.com/articles/consumerDrivenContracts.html
● https://www.thoughtworks.com/radar/techniques/
consumer-driven-contract-testing
And… What happened to Alice?
Oh yea! She implemented “Pact Tests”
and
lived happily ever-after!!
Questions
Thank You!

More Related Content

What's hot

Server Side Javascript : how to start ?
Server Side Javascript : how to start ?Server Side Javascript : how to start ?
Server Side Javascript : how to start ?
Quentin Adam
 
Performance optimisation with GraphQL
Performance optimisation with GraphQLPerformance optimisation with GraphQL
Performance optimisation with GraphQL
yann_s
 
29
2929
@IndeedEng: Tokens and Millicents - technical challenges in launching Indeed...
@IndeedEng:  Tokens and Millicents - technical challenges in launching Indeed...@IndeedEng:  Tokens and Millicents - technical challenges in launching Indeed...
@IndeedEng: Tokens and Millicents - technical challenges in launching Indeed...
indeedeng
 
THE SCIENCE AND ART OF BACKWARDS COMPATIBILITY
THE SCIENCE AND ART OF BACKWARDS COMPATIBILITYTHE SCIENCE AND ART OF BACKWARDS COMPATIBILITY
THE SCIENCE AND ART OF BACKWARDS COMPATIBILITY
Informatics Summit
 
Behavioral Driven Development
Behavioral Driven Development Behavioral Driven Development
Behavioral Driven Development
Cprime
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Gáspár Nagy
 
[@IndeedEng] Managing Experiments and Behavior Dynamically with Proctor
[@IndeedEng] Managing Experiments and Behavior Dynamically with Proctor[@IndeedEng] Managing Experiments and Behavior Dynamically with Proctor
[@IndeedEng] Managing Experiments and Behavior Dynamically with Proctor
indeedeng
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
POSSCON
 
Entity framework db model的驗證機制 20130914
Entity framework db model的驗證機制 20130914Entity framework db model的驗證機制 20130914
Entity framework db model的驗證機制 20130914LearningTech
 
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIOJumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Josh Cypher
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
Daniel Kummer
 
JOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and ReduxJOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and Redux
Jordan Open Source Association
 
Leveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APILeveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk API
Salesforce Developers
 
20150309 seven core principles of meteor
20150309 seven core principles of meteor20150309 seven core principles of meteor
20150309 seven core principles of meteor
Rick Wehrle
 
London React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor CharyparLondon React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor Charypar
React London Community
 
React js
React jsReact js
React js
Rajesh Kolla
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomas
intuit_india
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testing
PetrosPlakogiannis
 
From ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcing
Emanuele DelBono
 

What's hot (20)

Server Side Javascript : how to start ?
Server Side Javascript : how to start ?Server Side Javascript : how to start ?
Server Side Javascript : how to start ?
 
Performance optimisation with GraphQL
Performance optimisation with GraphQLPerformance optimisation with GraphQL
Performance optimisation with GraphQL
 
29
2929
29
 
@IndeedEng: Tokens and Millicents - technical challenges in launching Indeed...
@IndeedEng:  Tokens and Millicents - technical challenges in launching Indeed...@IndeedEng:  Tokens and Millicents - technical challenges in launching Indeed...
@IndeedEng: Tokens and Millicents - technical challenges in launching Indeed...
 
THE SCIENCE AND ART OF BACKWARDS COMPATIBILITY
THE SCIENCE AND ART OF BACKWARDS COMPATIBILITYTHE SCIENCE AND ART OF BACKWARDS COMPATIBILITY
THE SCIENCE AND ART OF BACKWARDS COMPATIBILITY
 
Behavioral Driven Development
Behavioral Driven Development Behavioral Driven Development
Behavioral Driven Development
 
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
Behavior Driven Web UI Automation with Selenium and Cucumber/SpecFlow (BDDx L...
 
[@IndeedEng] Managing Experiments and Behavior Dynamically with Proctor
[@IndeedEng] Managing Experiments and Behavior Dynamically with Proctor[@IndeedEng] Managing Experiments and Behavior Dynamically with Proctor
[@IndeedEng] Managing Experiments and Behavior Dynamically with Proctor
 
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP AnywayI Know It Was MEAN, But I Cut the Cord to LAMP Anyway
I Know It Was MEAN, But I Cut the Cord to LAMP Anyway
 
Entity framework db model的驗證機制 20130914
Entity framework db model的驗證機制 20130914Entity framework db model的驗證機制 20130914
Entity framework db model的驗證機制 20130914
 
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIOJumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
Jumpstarting Testing In Your Organization with Selenium, Cucumber, & WebdriverIO
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
JOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and ReduxJOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and Redux
 
Leveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APILeveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk API
 
20150309 seven core principles of meteor
20150309 seven core principles of meteor20150309 seven core principles of meteor
20150309 seven core principles of meteor
 
London React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor CharyparLondon React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor Charypar
 
React js
React jsReact js
React js
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomas
 
Timings API: Performance Assertion during the functional testing
 Timings API: Performance Assertion during the functional testing Timings API: Performance Assertion during the functional testing
Timings API: Performance Assertion during the functional testing
 
From ActiveRecord to EventSourcing
From ActiveRecord to EventSourcingFrom ActiveRecord to EventSourcing
From ActiveRecord to EventSourcing
 

Viewers also liked

Java se7 features
Java se7 featuresJava se7 features
Java se7 features
Kumaraswamy M
 
Continuous Testing using Shippable and Docker
Continuous Testing using Shippable and DockerContinuous Testing using Shippable and Docker
Continuous Testing using Shippable and Docker
Mukta Aphale
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for Testing
Mukta Aphale
 
Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...
Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...
Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...
Pierre Vincent
 
Lean UX and Design winning mobile apps
Lean UX and Design winning mobile appsLean UX and Design winning mobile apps
Lean UX and Design winning mobile apps
Kosala Nuwan Perera
 
Continuous Testing
Continuous TestingContinuous Testing
Continuous Testing
Crevise Technologies
 
About Agile Testing Alliance (ATA)
About Agile Testing Alliance (ATA)About Agile Testing Alliance (ATA)
About Agile Testing Alliance (ATA)
Agile Testing Alliance
 
Certified professional - DevOps Foundation (CP-DOF) course information
Certified professional - DevOps Foundation (CP-DOF) course informationCertified professional - DevOps Foundation (CP-DOF) course information
Certified professional - DevOps Foundation (CP-DOF) course information
DevOps++ Alliance
 

Viewers also liked (8)

Java se7 features
Java se7 featuresJava se7 features
Java se7 features
 
Continuous Testing using Shippable and Docker
Continuous Testing using Shippable and DockerContinuous Testing using Shippable and Docker
Continuous Testing using Shippable and Docker
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for Testing
 
Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...
Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...
Consumer-driven contracts: avoid microservices integration hell! (LondonCD - ...
 
Lean UX and Design winning mobile apps
Lean UX and Design winning mobile appsLean UX and Design winning mobile apps
Lean UX and Design winning mobile apps
 
Continuous Testing
Continuous TestingContinuous Testing
Continuous Testing
 
About Agile Testing Alliance (ATA)
About Agile Testing Alliance (ATA)About Agile Testing Alliance (ATA)
About Agile Testing Alliance (ATA)
 
Certified professional - DevOps Foundation (CP-DOF) course information
Certified professional - DevOps Foundation (CP-DOF) course informationCertified professional - DevOps Foundation (CP-DOF) course information
Certified professional - DevOps Foundation (CP-DOF) course information
 

Similar to CDC Tests - Integration Tests cant be made simpler than this!

ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
Agile Testing Alliance
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
Kevin Sutter
 
The case for consumer-driven contracts
The case for consumer-driven contractsThe case for consumer-driven contracts
The case for consumer-driven contracts
DiUS
 
AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7
WASdev Community
 
AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7
Kevin Sutter
 
Deploy with Confidence using Pact Go!
Deploy with Confidence using Pact Go!Deploy with Confidence using Pact Go!
Deploy with Confidence using Pact Go!
DiUS
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Eventstkramar
 
Integrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST APIIntegrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST API
Espresso Logic
 
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS'sMongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
MongoDB
 
HTML5 Server Sent Events/JSF JAX 2011 Conference
HTML5 Server Sent Events/JSF  JAX 2011 ConferenceHTML5 Server Sent Events/JSF  JAX 2011 Conference
HTML5 Server Sent Events/JSF JAX 2011 ConferenceRoger Kitain
 
Presto+MySQLで分散SQL
Presto+MySQLで分散SQLPresto+MySQLで分散SQL
Presto+MySQLで分散SQL
Sadayuki Furuhashi
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsCarol McDonald
 
Event Driven Architecture (Integration Tech Event 2019)
Event Driven Architecture (Integration Tech Event 2019)Event Driven Architecture (Integration Tech Event 2019)
Event Driven Architecture (Integration Tech Event 2019)
Jeppe Cramon
 
Con fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhaktiCon fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhaktiBhakti Mehta
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
Sachin G Kulkarni
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
Antonio Peric-Mazar
 
[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기
[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기
[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기lanslote
 
Consumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHPConsumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHP
Andy Kelk
 
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
VMware Tanzu
 

Similar to CDC Tests - Integration Tests cant be made simpler than this! (20)

ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
 
The case for consumer-driven contracts
The case for consumer-driven contractsThe case for consumer-driven contracts
The case for consumer-driven contracts
 
AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7
 
AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7
 
Deploy with Confidence using Pact Go!
Deploy with Confidence using Pact Go!Deploy with Confidence using Pact Go!
Deploy with Confidence using Pact Go!
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Events
 
Integrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST APIIntegrate MongoDB & SQL data with a single REST API
Integrate MongoDB & SQL data with a single REST API
 
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS'sMongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
 
HTML5 Server Sent Events/JSF JAX 2011 Conference
HTML5 Server Sent Events/JSF  JAX 2011 ConferenceHTML5 Server Sent Events/JSF  JAX 2011 Conference
HTML5 Server Sent Events/JSF JAX 2011 Conference
 
Presto+MySQLで分散SQL
Presto+MySQLで分散SQLPresto+MySQLで分散SQL
Presto+MySQLで分散SQL
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
Rest
RestRest
Rest
 
Event Driven Architecture (Integration Tech Event 2019)
Event Driven Architecture (Integration Tech Event 2019)Event Driven Architecture (Integration Tech Event 2019)
Event Driven Architecture (Integration Tech Event 2019)
 
Con fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhaktiCon fess 2013-sse-websockets-json-bhakti
Con fess 2013-sse-websockets-json-bhakti
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기
[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기
[SharePoint Korea Conference 2013 / 강율구] Sharepoint 스마트하게 개발하기
 
Consumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHPConsumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHP
 
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
Cloud Foundry Cookbook: Recipes for a Successful Cloud Foundry Deployment in ...
 

Recently uploaded

Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 

Recently uploaded (20)

Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 

CDC Tests - Integration Tests cant be made simpler than this!

  • 2. Based on a true (truly imaginary?) story! Alice • our main character in the story • Senior Dev in FreshMock.com • Owns a “Subscription Service” • Friday the 13th!
  • 3. What happened on Friday the 13th? ● “CustomerInfo Service”’s change ● Updates a property in the response object ● Changes “customer” (which returns a list of customers) to “customers” (Grammatically correct though! :( ) ● BUT this one letter change BROKE the “Subscription Service”
  • 4. Here comes the bigger question… Why didn't our tests catch this??
  • 5. So how do you test? ● Mock the dependencies Subscription Service Mock CustomerInfo Service Request Response
  • 6. Unit Tests ● Similarly the “CustomerInfo Service”, has a mock client for “Subscription Service” ● It DID fail! ● But then “I updated my test because I know this is an expected failure! ”
  • 7. Unit Tests ● Why do we still do it? • Fast • Easy to setup • No Flakiness! • Ensures functionality of a specific microservice
  • 8. Integration Tests Subscription Service CustomerInfo Service Request Response
  • 9. Integration Tests ● Slower ● Set up time (“Stack Setup!”) ● More flakiness ● More infrastructure! ● End up doing an E2E tests
  • 10. Other types of Tests •End-to-End Tests •Manual Tests •Again, • Stack Setup! • Slower (E2E tests) • More flakiness • Not failing fast!
  • 11. Solution? Is there a better way to identify these kind of issues?
  • 12.
  • 13. Pact Tests • Also called “Contract Tests” • Consumer Driven Contract Tests (CDC Tests) • Tool Used: Pact • A Contract is a collection of agreements between a client (Consumer) and an API (Provider) that describes the interactions that can take place between them.
  • 14. Pact Tests? What are these? Subscription Service CustomerInfo Service Request Response Consumer Provider
  • 15. Sends response for assertions Pact Tests: Consumer Side Tests Set Expectations Pact Mock Provider Tests invoke code Source Code Sends HTTP Requests Sends expected response
  • 16. Is it just another Mock HTTP Server? Subscription Service CustomerInfo Service Request Response Consumer Provider
  • 17. The Pact File • Every HTTP Request and Response is captured • Standard way of representing interactions - JSON file • This is shared with the Provider. • Explains everything that a consumer expects from the Provider - the endpoints, query params, header and the response objects.
  • 18. Pact Tests:Provider Side CustomerInfo Service Replay each HTTP Request Get real HTTP Response Provider Pact File Compares real and mock responses
  • 19. Provider States • Get billing address of customer with id=777 Subscription Service CustomerInfo Service Request Response Consumer Provider Request Response ?
  • 20. state: cust_id=777 @ DB Provider States • Get billing address of customer with id=777 Subscription Service CustomerInfo Service Request Response Consumer Provider Request Response state: cust_id=777 @ DB state: cust_id=777 @ DB
  • 21. Sharing Pact Files Filesystem Cloud Pact BrokerCI Build Artefact
  • 22. Sharing Pact Files - Pact Broker • Pact Broker - a repo for storing pacts • Auto-generated documentation • The ability to tag a Pact (i.e. “prod") - versioning pacts • Network Graph
  • 23. Sharing Pact Files - Pact Broker
  • 24. Automating Pact Tests • When a new Pact is published, how does the Provider get notified? Manual Trigger Pact Broker Webhook Swagger Validator
  • 25. Advantages •Eliminates Wrong Assumptions •Enables communication •Very less setup time! •No extra infrastructure •Fast in Execution •Fails Fast •No flakiness! •Easy to debug
  • 26. DEMO Freshapps DevPortal Freshapps Activities Request Response Consumer Provider
  • 27. Consumer Side : Setup Mock Server Pact.service_consumer 'DevPortal' do end
  • 28. Consumer Side : Setup Mock Server Pact.service_consumer 'DevPortal' do has_pact_with "Freshapps Activities" do end end
  • 29. Consumer Side : Setup Mock Server Pact.service_consumer 'DevPortal' do has_pact_with "Freshapps Activities" do mock_service :freshapps_activities do port 3005 end end end
  • 30. Consumer Side : Setup Expectations freshapps_activities.given(“all activities without role param")
  • 31. Consumer Side : Setup Expectations freshapps_activities.given(“all activities without role param") .upon_receiving("a request for all activities") .with( method: :get, path: '/all/activities.json', query: { page: '1', account_id: '1' }, headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'} )
  • 32. Consumer Side : Setup Expectations freshapps_activities.given(“all activities without role param") .upon_receiving("a request for all activities") .with( method: :get, path: '/all/activities.json', query: { page: '1', account_id: '1' }, headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'} ) .will_respond_with( status: 422, headers: { 'Content-Type' => 'application/json; charset=utf-8' }, body: { "error_msg" => "Required parameter missing" } )
  • 33. Consumer Side : Make Request & Assert resp = FreshappsActivitiesClient.get_activities(path, query, header)
  • 34. Consumer Side : Make Request & Assert resp = FreshappsActivitiesClient.get_activities(path, query, header) expected_response = { "error_msg" => "Required parameter missing" } expect(resp.parsed_response.inspect).to eq(expected_response.inspect)
  • 35. Generated Pact File { "consumer": { "name": "DevPortal" }, "provider": { "name": "Freshapps Activities" }, "interactions": [ { "description": "a request for all activities", "provider_state": "all activities without role param", "request": { "method": "get", "path": "/all/activities.json", "query": "page=1&account_id=1", "headers": { "Content-Type": "application/json", "Accept": "application/json" } }, "response": { "status": 422, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "error_msg": "Required parameter missing" } } } ], "metadata": { "pactSpecificationVersion": "1.0.0" } }
  • 36. Provider Side : Make Request & Assert Pact.service_provider 'Freshapps Activities' do end
  • 37. Provider Side : Make Request & Assert Pact.service_provider 'Freshapps Activities' do honours_pact_with 'DevPortal' do end end
  • 38. Provider Side : Make Request & Assert Pact.service_provider 'Freshapps Activities' do honours_pact_with 'DevPortal' do pact_uri "../freshapps_devportal/spec/pacts/devportal-freshapps_activities.json" end end end
  • 39. Provider Side : Setup Test Data Pact.provider_states_for "DevPortal" do provider_state "all activities without role param" do end end Remember: Consumer Assumed: freshapps_activities.given(“ all activities without role param")
  • 40. Provider Side : Setup Test Data Pact.provider_states_for "DevPortal" do provider_state "all activities without role param" do set_up do factory :activity do account_id 1 user_id 1 extension_id 2 version_id 2 activity_type 'Extension' visibility 1 activity { 'extension_id' => '2', 'name' => 'Sample Extension’} end end end end Remember: Consumer Assumed: freshapps_activities.given(“ all activities without role param")
  • 41. Provider Side : Pact Verify Failure
  • 42. Provider Side : Pact Verify Success
  • 43. pact.io • Working examples and documentations available at pact.io • Supports: Ruby, Java, .NET • Beta: JS,Python, Swift, Go • https://groups.google.com/forum/#!forum/pact-support • https://gitter.im/realestate-com-au/pact • Other Similar Tools: • Pacto (by Thoughtworks - but not maintained though.)
  • 44. References ● To know about Consumer Driven Contract: https:// martinfowler.com/articles/consumerDrivenContracts.html ● https://www.thoughtworks.com/radar/techniques/ consumer-driven-contract-testing
  • 45. And… What happened to Alice? Oh yea! She implemented “Pact Tests” and lived happily ever-after!!