SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
Consumer-Driven Contract Testing
Implementing a scalable testing strategy for Microservices
Paulo Clavijo Esteban
@pclavijo - January 2018
About me
Principal Software Engineer at Dell-EMC
Organizer Cork Software Crafters meetup
Paulo Clavijo @pclavijo - January 2018
Cork Software CraftersPaulo Clavijo Esteban @pclavijo
paucls.wordpress.com
github.com/paucls
Context
● < 2014 - Monolithic systems
○ Unit tests, Integrations Tests and slow Webdriver E2E tests.
● 2014 - Transition to Microservices architecture and web apps
○ Services tested with Unit tests, Component tests.
○ Web apps with Unit tests and E2E tests using a stub backend.
○ System Integration tests limited to high-value User Journeys.
● 2016 - CD Pipelines
○ Teams doing Continuous Delivery. Feature Toggles.
○ Continuous Deployment only to Staging.
● 2017 - Implemented Consumer-Driven Contract Tests
○ Solved the REST APIs integration issues. Full CD to Production.
Paulo Clavijo @pclavijo - January 2018
Context
A previous attempt of using Contract Tests didn’t work out
● Contract testing purpose and value was not understood properly.
● Introduced partially without bringing real value.
○ Only consumer contracts for Java services without corresponding providers test.
○ Not used on Web apps.
○ No integration with CI/CD pipeline, pull requests.
○ Overhead of writing them didn’t pay off.
● Tests scope was too broad.
● Shared client libraries. No Front-end first / CDC flow.
Paulo Clavijo @pclavijo - January 2018
The Challenge
Multiple feature teams, applications, microservices. Independent
deployments, ...
… REST APIs integration issues.
How to test collaboration between system components?
● Isolated Component Tests, Test Doubles and the Test
Symmetry problem
● Integration Tests?
● System End-to-end tests?
Web-app
to Service
Service to
Service
Paulo Clavijo @pclavijo - January 2018
Contract Tests
Traditionally understood as a separate set of tests that checks that all the calls against
your test doubles return the same results as a call to the remote service would.
Consumer
Remote
Service
Test Double
Unit tests Contract tests
Paulo Clavijo @pclavijo - January 2018
Consumer-Driven Contract Tests
Unit tests in both sides where consumers detail clearly what are the interactions and
behaviours expected from the provider API.
Consumer Provider
Consumer
Contracts
Test Double
Verify on providerRecord consumer
expectations
Unit tests Unit tests
Paulo Clavijo @pclavijo - January 2018
Consumer-Driven Contract Tests
Consumer Driven Contracts (CDC) is a pattern that drives the development of the Provider
from its Consumer's point of view. It is TDD for services.
It is possible to make changes on a provider knowing that consumers won't be impacted!
Consumer A
Consumer B
Consumer C
Provider
Consumer-Driven
Contract
{ Id: 100,
name: “A task” }
{ Id: 100,
name: “A task”
expedite: true }
{ Id: 100,
duration: 20 }
{ Id: 100,
name: “A task”,
expedite: true,
duration: 20 }
Consumer Contract A
Consumer Contract B
Consumer Contract C
Paulo Clavijo @pclavijo - January 2018
Consumer-Driven Contract Tests
They do not test the behaviour of the service in depth but that the inputs and outputs of
service calls contain required attributes.
https://martinfowler.com/articles/microservice-testing
Paulo Clavijo @pclavijo - January 2018
Consumer-Driven Contracts
Great for developing and testing intra-organisation microservices.
● You (or your team/organisation/partner organisation) control the development of both the
consumer and the provider.
● The requirements of the consumer(s) are going to be used to drive the features of the
provider.
● There is a small enough number of consumers for a given provider that the provider team can
manage an individual relationship with each consumer team.
https://docs.pact.io/documentation/what_is_pact_good_for.html
Paulo Clavijo @pclavijo - January 2018
Pact
● Some of the tools that support Consumer-Driven Contract Testing are Pact and
Spring Cloud Contract.
● We chose Pact because:
○ Generation of contracts from the code
○ Provider verification (pact-jvm-provider-junit)
○ Supports multiple languages JVM, Node, JS web apps, …
○ Pact Specification
○ Pact Broker
Paulo Clavijo @pclavijo - January 2018
Pact Broker
● Helps managing, versioning and distributing
contracts.
● Great tool to visualize contracts and system
relationships (dependency graph).
● Contracts as a form of “Live Documentation” for
APIs and interactions between components.
Paulo Clavijo @pclavijo - January 2018
Implementing CDC
CDC on the Consumer side
Consumer
Contracts
Provider
Contract
Tests
1) Define expected interactions
2) Tests the API Client
code on the consumer
Provider
Contract
Tests
Consumer
Contract
Tests
4) Generates contracts
Consumer
API Client
Pact Mock
Service
3) Verify interactions
Paulo Clavijo @pclavijo - January 2018
CDC on the Consumer side
1) Define expected interactions
2) Tests the API Client code
3) Verify interactions
Paulo Clavijo @pclavijo - January 2018
CDC on the Consumer side
4) Pact Mock Service generates contract
files for successful tests
These contracts, in a CDC flow, can
now be shared and used to drive the
development of the provider.
Paulo Clavijo @pclavijo - January 2018
Contract Testing on the Provider side
Consumer
Contracts
Provider
A
P
I
Provider
Contract
Tests
1) Pact auto-generates provider tests
3) Tests the provider
Provider
Contract
Tests
Provider
Contract
Tests
2) Set-up provider state
Paulo Clavijo @pclavijo - January 2018
Contract Testing on the Provider side
Auto-generated Pact provider contract tests
Paulo Clavijo @pclavijo - January 2018
Paulo Clavijo @pclavijo - January 2018
Contract Testing on the Provider side
Pact uses the state description on the
contract to determine which set-up logic
needs to be executed before running a
generated test.
Contract Testing on the Provider side
Let’s implement a new end-point ...
Contract Testing on the Provider side
Let’s implement a new end-point ...
Contract Testing on the Provider side
Tests fail when changes in Provider impacts a Consumer
Flexible Matching
Pact provides flexible matching by regular
expressions or type.
Paulo Clavijo @pclavijo - January 2018
Defining Interactions
When we define the expected interactions between a consumer and a provider, the ‘state’ and
‘uponReceiving’ descriptions used should be written in a consistent style.
Later on, on the provider side, Pact uses the uponReceiving description to name the auto-generated
test, and the state description is used to find a corresponding test state.
// Expected Interaction
provider.addInteraction({
state: 'a task with id task-id exists',
uponReceiving: 'a request to delete task task-id',
withRequest: {method: 'DELETE', path: '/tasks/task-id'},
willRespondWith: {status: 204}
});
Paulo Clavijo @pclavijo - January 2018
Defining Interactions
Examples
Successful interaction where data is returned
state: ‘tasks for project with id project-id exist’,
uponReceiving: ‘a request to get tasks for that project’
Successful interaction where no data is returned
state: ‘tasks for project with id project-id do not exist’,
uponReceiving: ‘a request to get tasks for that project’
404 error interaction
state: ‘project project-id does not exist’,
uponReceiving: ‘a request to get tasks for that project’
Domain validation error interaction
state: ‘a task task-id exists and domain rules exist that prevent its
modification’,
uponReceiving: ‘a request to update that task’
Successful interaction where data is created
state: ‘a project with name project-1 does not exist’,
uponReceiving: ‘a request to create a project with name project-1’
Paulo Clavijo @pclavijo - January 2018
Live Documentation
Contracts are not only used by the tests, we also intent them to be user-friendly. Developers
can consult contracts in the Pact Broker who shows them in a nice documentation style.
Paulo Clavijo @pclavijo - January 2018
CDC in our pipeline
Paulo Clavijo @pclavijo - January 2018
CDC vs Contract Tests
TDD is more than having Unit Tests …
… CDC is more than having Contract Tests
Think in it as Outside-In TDD for a whole system!
Is what we do, a technique and attitude, discipline on the
design and development flow.
Paulo Clavijo @pclavijo - January 2018
What is next?
● Pact v3
○ Contract testing for messages (for services that communicate via event streams and message
queues)
● Pact v4
○ Matching times and dates in a cross-platform manner
○ Additional Matchers
● … Beyond REST APIs. GraphQL?
○ Servers publish a statically typed system specific to their application, and GraphQL provides a
unified language to query data within the constraints of that type system.
Paulo Clavijo @pclavijo - January 2018
Further reading
● Implementing Consumer-Driven Contract tests in Angular, Paulo Clavijo
https://paucls.wordpress.com/2017/08/04/pact-consumer-driven-contract-imple
mentation-in-angular
● Configure Pact JS Consumer Contract tests in Angular, Paulo Clavijo
https://paucls.wordpress.com/2017/08/04/configure-pact-js-consumer-contract-
tests-in-angular
● Sample project on Provider Side
https://github.com/paucls/task_list_api-kotlin-pact
Paulo Clavijo @pclavijo - January 2018
References
● ContractTest, Martin Fowler. https://martinfowler.com/bliki/ContractTest.html
● Pact documentation https://docs.pact.io/documentation/implementation_guides.html
● Testing Strategies in a Microservice Architecture, Toby Clemson
https://martinfowler.com/articles/microservice-testing/
● Integrated Tests Are A Scam, J.B. Rainsberger
http://blog.thecodewhisperer.com/permalink/integrated-tests-are-a-scam
● Consumer-Driven Contracts: A Service Evolution Pattern, Ian Robinson
https://www.martinfowler.com/articles/consumerDrivenContracts.html
● Microservices, Flexible Software Architecture. Eberhard Wolff.
● Contract testing with GraphQL, Andreas Marek
https://www.andimarek.com/post/contract-testing-graphql
● https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-junit
Paulo Clavijo @pclavijo - January 2018
Consumer-Driven Contract Testing
Implementing a scalable testing strategy for Microservices
Paulo Clavijo Esteban
@pclavijo - January 2018

Weitere ähnliche Inhalte

Was ist angesagt?

Spring Cloud Contract And Your Microservice Architecture
Spring Cloud Contract And Your Microservice ArchitectureSpring Cloud Contract And Your Microservice Architecture
Spring Cloud Contract And Your Microservice ArchitectureMarcin Grzejszczak
 
Platform Engineering
Platform EngineeringPlatform Engineering
Platform EngineeringOpsta
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQLVMware Tanzu
 
Platform engineering 101
Platform engineering 101Platform engineering 101
Platform engineering 101Sander Knape
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquareApigee | Google Cloud
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud VMware Tanzu
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentationVibhor Grover
 
Service Level Terminology : SLA ,SLO & SLI
Service Level Terminology : SLA ,SLO & SLIService Level Terminology : SLA ,SLO & SLI
Service Level Terminology : SLA ,SLO & SLIKnoldus Inc.
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principlesSanjoy Kumar Roy
 
Reactive Microservices with Quarkus
Reactive Microservices with QuarkusReactive Microservices with Quarkus
Reactive Microservices with QuarkusNiklas Heidloff
 
RESTful services
RESTful servicesRESTful services
RESTful servicesgouthamrv
 
Getting started with Site Reliability Engineering (SRE)
Getting started with Site Reliability Engineering (SRE)Getting started with Site Reliability Engineering (SRE)
Getting started with Site Reliability Engineering (SRE)Abeer R
 
Highlights of WSO2 API Manager 4.0.0
Highlights of WSO2 API Manager 4.0.0Highlights of WSO2 API Manager 4.0.0
Highlights of WSO2 API Manager 4.0.0WSO2
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WSIndicThreads
 
An Introduction To Jenkins
An Introduction To JenkinsAn Introduction To Jenkins
An Introduction To JenkinsKnoldus Inc.
 

Was ist angesagt? (20)

Spring Cloud Contract And Your Microservice Architecture
Spring Cloud Contract And Your Microservice ArchitectureSpring Cloud Contract And Your Microservice Architecture
Spring Cloud Contract And Your Microservice Architecture
 
Platform Engineering
Platform EngineeringPlatform Engineering
Platform Engineering
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQL
 
Chaos Engineering
Chaos EngineeringChaos Engineering
Chaos Engineering
 
Platform engineering 101
Platform engineering 101Platform engineering 101
Platform engineering 101
 
React context
React context  React context
React context
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at Square
 
DevOps & SRE at Google Scale
DevOps & SRE at Google ScaleDevOps & SRE at Google Scale
DevOps & SRE at Google Scale
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
Service Level Terminology : SLA ,SLO & SLI
Service Level Terminology : SLA ,SLO & SLIService Level Terminology : SLA ,SLO & SLI
Service Level Terminology : SLA ,SLO & SLI
 
Spring Cloud Gateway
Spring Cloud GatewaySpring Cloud Gateway
Spring Cloud Gateway
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principles
 
Reactive Microservices with Quarkus
Reactive Microservices with QuarkusReactive Microservices with Quarkus
Reactive Microservices with Quarkus
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Getting started with Site Reliability Engineering (SRE)
Getting started with Site Reliability Engineering (SRE)Getting started with Site Reliability Engineering (SRE)
Getting started with Site Reliability Engineering (SRE)
 
Highlights of WSO2 API Manager 4.0.0
Highlights of WSO2 API Manager 4.0.0Highlights of WSO2 API Manager 4.0.0
Highlights of WSO2 API Manager 4.0.0
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WS
 
An Introduction To Jenkins
An Introduction To JenkinsAn Introduction To Jenkins
An Introduction To Jenkins
 

Ähnlich wie Consumer-Driven Contract Testing

TDD for Microservices
TDD for MicroservicesTDD for Microservices
TDD for MicroservicesVMware Tanzu
 
Consumer Driven Contracts
Consumer Driven ContractsConsumer Driven Contracts
Consumer Driven ContractsVisuality
 
Consumer Driven Contracts for microservices
Consumer Driven Contracts for microservicesConsumer Driven Contracts for microservices
Consumer Driven Contracts for microservicesReshmi Krishna
 
Consumer driven contracts in java world
Consumer driven contracts in java worldConsumer driven contracts in java world
Consumer driven contracts in java worldYura Nosenko
 
How to Ensure your Definition of Done is Well Done not Half-Baked
How to Ensure your Definition of Done is Well Done not Half-BakedHow to Ensure your Definition of Done is Well Done not Half-Baked
How to Ensure your Definition of Done is Well Done not Half-BakedSusan Schanta
 
Webinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
Webinar-From user stories to automated acceptance tests with BDD-Eduardo RiolWebinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
Webinar-From user stories to automated acceptance tests with BDD-Eduardo RiolatSistemas
 
Testing microservices, contract testing
Testing microservices, contract testingTesting microservices, contract testing
Testing microservices, contract testingDaria Golub
 
Drive Business Excellence with Outcomes-Based Contracting: The OBC Toolkit
Drive Business Excellence with Outcomes-Based Contracting: The OBC ToolkitDrive Business Excellence with Outcomes-Based Contracting: The OBC Toolkit
Drive Business Excellence with Outcomes-Based Contracting: The OBC ToolkitCAST
 
Expo qa from user stories to automated acceptance tests with bdd
Expo qa   from user stories to automated acceptance tests with bddExpo qa   from user stories to automated acceptance tests with bdd
Expo qa from user stories to automated acceptance tests with bddEduardo Riol
 
Micro-service delivery - without the pitfalls
Micro-service delivery - without the pitfallsMicro-service delivery - without the pitfalls
Micro-service delivery - without the pitfallsSeb Rose
 
Consumer Driven Contracts (DDD Perth 2016)
Consumer Driven Contracts (DDD Perth 2016)Consumer Driven Contracts (DDD Perth 2016)
Consumer Driven Contracts (DDD Perth 2016)Rob Crowley
 
Microservices: Consumer Driven Contracts in Practice
Microservices: Consumer Driven Contracts in PracticeMicroservices: Consumer Driven Contracts in Practice
Microservices: Consumer Driven Contracts in PracticeQaiser Mazhar
 
Guidewire Connections 2023 DE-4 Using AI to Accelerate Application Integration
Guidewire Connections 2023 DE-4 Using AI to Accelerate Application IntegrationGuidewire Connections 2023 DE-4 Using AI to Accelerate Application Integration
Guidewire Connections 2023 DE-4 Using AI to Accelerate Application IntegrationBrianPetrini
 
software sourcing presentation
software sourcing presentationsoftware sourcing presentation
software sourcing presentationManoj Abraham
 
Take The Highway To A Successful It Project
Take The Highway To A Successful It ProjectTake The Highway To A Successful It Project
Take The Highway To A Successful It Projectsantosh singh
 
Asbo Vendor Performance Eval Chicago 092509
Asbo Vendor Performance Eval   Chicago   092509Asbo Vendor Performance Eval   Chicago   092509
Asbo Vendor Performance Eval Chicago 092509Richard Gay, CPPO, RSBO
 
gtFace: Scrum (presentation)
gtFace: Scrum (presentation)gtFace: Scrum (presentation)
gtFace: Scrum (presentation)kostienko2
 

Ähnlich wie Consumer-Driven Contract Testing (20)

TDD for Microservices
TDD for MicroservicesTDD for Microservices
TDD for Microservices
 
Consumer Driven Contracts
Consumer Driven ContractsConsumer Driven Contracts
Consumer Driven Contracts
 
Consumer Driven Contracts for microservices
Consumer Driven Contracts for microservicesConsumer Driven Contracts for microservices
Consumer Driven Contracts for microservices
 
Consumer driven contracts in java world
Consumer driven contracts in java worldConsumer driven contracts in java world
Consumer driven contracts in java world
 
How to Ensure your Definition of Done is Well Done not Half-Baked
How to Ensure your Definition of Done is Well Done not Half-BakedHow to Ensure your Definition of Done is Well Done not Half-Baked
How to Ensure your Definition of Done is Well Done not Half-Baked
 
Coherent REST API design
Coherent REST API designCoherent REST API design
Coherent REST API design
 
R.D.Fernandez et al - Software rates vs price of function points
R.D.Fernandez et al  - Software rates vs price of function pointsR.D.Fernandez et al  - Software rates vs price of function points
R.D.Fernandez et al - Software rates vs price of function points
 
Webinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
Webinar-From user stories to automated acceptance tests with BDD-Eduardo RiolWebinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
Webinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
 
Testing microservices, contract testing
Testing microservices, contract testingTesting microservices, contract testing
Testing microservices, contract testing
 
Agile Contracts
Agile ContractsAgile Contracts
Agile Contracts
 
Drive Business Excellence with Outcomes-Based Contracting: The OBC Toolkit
Drive Business Excellence with Outcomes-Based Contracting: The OBC ToolkitDrive Business Excellence with Outcomes-Based Contracting: The OBC Toolkit
Drive Business Excellence with Outcomes-Based Contracting: The OBC Toolkit
 
Expo qa from user stories to automated acceptance tests with bdd
Expo qa   from user stories to automated acceptance tests with bddExpo qa   from user stories to automated acceptance tests with bdd
Expo qa from user stories to automated acceptance tests with bdd
 
Micro-service delivery - without the pitfalls
Micro-service delivery - without the pitfallsMicro-service delivery - without the pitfalls
Micro-service delivery - without the pitfalls
 
Consumer Driven Contracts (DDD Perth 2016)
Consumer Driven Contracts (DDD Perth 2016)Consumer Driven Contracts (DDD Perth 2016)
Consumer Driven Contracts (DDD Perth 2016)
 
Microservices: Consumer Driven Contracts in Practice
Microservices: Consumer Driven Contracts in PracticeMicroservices: Consumer Driven Contracts in Practice
Microservices: Consumer Driven Contracts in Practice
 
Guidewire Connections 2023 DE-4 Using AI to Accelerate Application Integration
Guidewire Connections 2023 DE-4 Using AI to Accelerate Application IntegrationGuidewire Connections 2023 DE-4 Using AI to Accelerate Application Integration
Guidewire Connections 2023 DE-4 Using AI to Accelerate Application Integration
 
software sourcing presentation
software sourcing presentationsoftware sourcing presentation
software sourcing presentation
 
Take The Highway To A Successful It Project
Take The Highway To A Successful It ProjectTake The Highway To A Successful It Project
Take The Highway To A Successful It Project
 
Asbo Vendor Performance Eval Chicago 092509
Asbo Vendor Performance Eval   Chicago   092509Asbo Vendor Performance Eval   Chicago   092509
Asbo Vendor Performance Eval Chicago 092509
 
gtFace: Scrum (presentation)
gtFace: Scrum (presentation)gtFace: Scrum (presentation)
gtFace: Scrum (presentation)
 

Mehr von Paulo Clavijo

Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021Paulo Clavijo
 
User story slicing exercise
User story slicing exerciseUser story slicing exercise
User story slicing exercisePaulo Clavijo
 
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020Paulo Clavijo
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019Paulo Clavijo
 
Legacy Code and Refactoring Workshop - Session 1 - October 2019
Legacy Code and Refactoring Workshop - Session 1 - October 2019Legacy Code and Refactoring Workshop - Session 1 - October 2019
Legacy Code and Refactoring Workshop - Session 1 - October 2019Paulo Clavijo
 
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019Approval Testing & Mutation Testing - Cork Software Crafters - June 2019
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019Paulo Clavijo
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
TDD and Simple Design Workshop - Session 1 - November 2018
TDD and Simple Design Workshop - Session 1 - November 2018TDD and Simple Design Workshop - Session 1 - November 2018
TDD and Simple Design Workshop - Session 1 - November 2018Paulo Clavijo
 
Outside-in TDD with Test Doubles
Outside-in TDD with Test DoublesOutside-in TDD with Test Doubles
Outside-in TDD with Test DoublesPaulo Clavijo
 
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018Paulo Clavijo
 
ATDD - Desarrollo Dirigido por Test de Aceptación
ATDD - Desarrollo Dirigido por Test de AceptaciónATDD - Desarrollo Dirigido por Test de Aceptación
ATDD - Desarrollo Dirigido por Test de AceptaciónPaulo Clavijo
 
Tests Unitarios con JUnit 4
Tests Unitarios con JUnit 4Tests Unitarios con JUnit 4
Tests Unitarios con JUnit 4Paulo Clavijo
 
Gestión de Cambios de BBDD con LiquiBase
Gestión de Cambios de BBDD con LiquiBaseGestión de Cambios de BBDD con LiquiBase
Gestión de Cambios de BBDD con LiquiBasePaulo Clavijo
 
Introducción a Spring Roo
Introducción a Spring RooIntroducción a Spring Roo
Introducción a Spring RooPaulo Clavijo
 

Mehr von Paulo Clavijo (15)

Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021
 
User story slicing exercise
User story slicing exerciseUser story slicing exercise
User story slicing exercise
 
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
CI/CD non-breaking changes exercise - Cork Software Crafters - February 2020
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
 
Legacy Code and Refactoring Workshop - Session 1 - October 2019
Legacy Code and Refactoring Workshop - Session 1 - October 2019Legacy Code and Refactoring Workshop - Session 1 - October 2019
Legacy Code and Refactoring Workshop - Session 1 - October 2019
 
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019Approval Testing & Mutation Testing - Cork Software Crafters - June 2019
Approval Testing & Mutation Testing - Cork Software Crafters - June 2019
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
TDD and Simple Design Workshop - Session 1 - November 2018
TDD and Simple Design Workshop - Session 1 - November 2018TDD and Simple Design Workshop - Session 1 - November 2018
TDD and Simple Design Workshop - Session 1 - November 2018
 
Outside-in TDD with Test Doubles
Outside-in TDD with Test DoublesOutside-in TDD with Test Doubles
Outside-in TDD with Test Doubles
 
Angular and Redux
Angular and ReduxAngular and Redux
Angular and Redux
 
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
 
ATDD - Desarrollo Dirigido por Test de Aceptación
ATDD - Desarrollo Dirigido por Test de AceptaciónATDD - Desarrollo Dirigido por Test de Aceptación
ATDD - Desarrollo Dirigido por Test de Aceptación
 
Tests Unitarios con JUnit 4
Tests Unitarios con JUnit 4Tests Unitarios con JUnit 4
Tests Unitarios con JUnit 4
 
Gestión de Cambios de BBDD con LiquiBase
Gestión de Cambios de BBDD con LiquiBaseGestión de Cambios de BBDD con LiquiBase
Gestión de Cambios de BBDD con LiquiBase
 
Introducción a Spring Roo
Introducción a Spring RooIntroducción a Spring Roo
Introducción a Spring Roo
 

Kürzlich hochgeladen

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 

Kürzlich hochgeladen (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 

Consumer-Driven Contract Testing

  • 1. Consumer-Driven Contract Testing Implementing a scalable testing strategy for Microservices Paulo Clavijo Esteban @pclavijo - January 2018
  • 2. About me Principal Software Engineer at Dell-EMC Organizer Cork Software Crafters meetup Paulo Clavijo @pclavijo - January 2018 Cork Software CraftersPaulo Clavijo Esteban @pclavijo paucls.wordpress.com github.com/paucls
  • 3. Context ● < 2014 - Monolithic systems ○ Unit tests, Integrations Tests and slow Webdriver E2E tests. ● 2014 - Transition to Microservices architecture and web apps ○ Services tested with Unit tests, Component tests. ○ Web apps with Unit tests and E2E tests using a stub backend. ○ System Integration tests limited to high-value User Journeys. ● 2016 - CD Pipelines ○ Teams doing Continuous Delivery. Feature Toggles. ○ Continuous Deployment only to Staging. ● 2017 - Implemented Consumer-Driven Contract Tests ○ Solved the REST APIs integration issues. Full CD to Production. Paulo Clavijo @pclavijo - January 2018
  • 4. Context A previous attempt of using Contract Tests didn’t work out ● Contract testing purpose and value was not understood properly. ● Introduced partially without bringing real value. ○ Only consumer contracts for Java services without corresponding providers test. ○ Not used on Web apps. ○ No integration with CI/CD pipeline, pull requests. ○ Overhead of writing them didn’t pay off. ● Tests scope was too broad. ● Shared client libraries. No Front-end first / CDC flow. Paulo Clavijo @pclavijo - January 2018
  • 5. The Challenge Multiple feature teams, applications, microservices. Independent deployments, ... … REST APIs integration issues. How to test collaboration between system components? ● Isolated Component Tests, Test Doubles and the Test Symmetry problem ● Integration Tests? ● System End-to-end tests? Web-app to Service Service to Service Paulo Clavijo @pclavijo - January 2018
  • 6. Contract Tests Traditionally understood as a separate set of tests that checks that all the calls against your test doubles return the same results as a call to the remote service would. Consumer Remote Service Test Double Unit tests Contract tests Paulo Clavijo @pclavijo - January 2018
  • 7. Consumer-Driven Contract Tests Unit tests in both sides where consumers detail clearly what are the interactions and behaviours expected from the provider API. Consumer Provider Consumer Contracts Test Double Verify on providerRecord consumer expectations Unit tests Unit tests Paulo Clavijo @pclavijo - January 2018
  • 8. Consumer-Driven Contract Tests Consumer Driven Contracts (CDC) is a pattern that drives the development of the Provider from its Consumer's point of view. It is TDD for services. It is possible to make changes on a provider knowing that consumers won't be impacted! Consumer A Consumer B Consumer C Provider Consumer-Driven Contract { Id: 100, name: “A task” } { Id: 100, name: “A task” expedite: true } { Id: 100, duration: 20 } { Id: 100, name: “A task”, expedite: true, duration: 20 } Consumer Contract A Consumer Contract B Consumer Contract C Paulo Clavijo @pclavijo - January 2018
  • 9. Consumer-Driven Contract Tests They do not test the behaviour of the service in depth but that the inputs and outputs of service calls contain required attributes. https://martinfowler.com/articles/microservice-testing Paulo Clavijo @pclavijo - January 2018
  • 10. Consumer-Driven Contracts Great for developing and testing intra-organisation microservices. ● You (or your team/organisation/partner organisation) control the development of both the consumer and the provider. ● The requirements of the consumer(s) are going to be used to drive the features of the provider. ● There is a small enough number of consumers for a given provider that the provider team can manage an individual relationship with each consumer team. https://docs.pact.io/documentation/what_is_pact_good_for.html Paulo Clavijo @pclavijo - January 2018
  • 11. Pact ● Some of the tools that support Consumer-Driven Contract Testing are Pact and Spring Cloud Contract. ● We chose Pact because: ○ Generation of contracts from the code ○ Provider verification (pact-jvm-provider-junit) ○ Supports multiple languages JVM, Node, JS web apps, … ○ Pact Specification ○ Pact Broker Paulo Clavijo @pclavijo - January 2018
  • 12. Pact Broker ● Helps managing, versioning and distributing contracts. ● Great tool to visualize contracts and system relationships (dependency graph). ● Contracts as a form of “Live Documentation” for APIs and interactions between components. Paulo Clavijo @pclavijo - January 2018
  • 14. CDC on the Consumer side Consumer Contracts Provider Contract Tests 1) Define expected interactions 2) Tests the API Client code on the consumer Provider Contract Tests Consumer Contract Tests 4) Generates contracts Consumer API Client Pact Mock Service 3) Verify interactions Paulo Clavijo @pclavijo - January 2018
  • 15. CDC on the Consumer side 1) Define expected interactions 2) Tests the API Client code 3) Verify interactions Paulo Clavijo @pclavijo - January 2018
  • 16. CDC on the Consumer side 4) Pact Mock Service generates contract files for successful tests These contracts, in a CDC flow, can now be shared and used to drive the development of the provider. Paulo Clavijo @pclavijo - January 2018
  • 17. Contract Testing on the Provider side Consumer Contracts Provider A P I Provider Contract Tests 1) Pact auto-generates provider tests 3) Tests the provider Provider Contract Tests Provider Contract Tests 2) Set-up provider state Paulo Clavijo @pclavijo - January 2018
  • 18. Contract Testing on the Provider side Auto-generated Pact provider contract tests Paulo Clavijo @pclavijo - January 2018
  • 19. Paulo Clavijo @pclavijo - January 2018 Contract Testing on the Provider side Pact uses the state description on the contract to determine which set-up logic needs to be executed before running a generated test.
  • 20. Contract Testing on the Provider side Let’s implement a new end-point ...
  • 21. Contract Testing on the Provider side Let’s implement a new end-point ...
  • 22. Contract Testing on the Provider side Tests fail when changes in Provider impacts a Consumer
  • 23. Flexible Matching Pact provides flexible matching by regular expressions or type. Paulo Clavijo @pclavijo - January 2018
  • 24. Defining Interactions When we define the expected interactions between a consumer and a provider, the ‘state’ and ‘uponReceiving’ descriptions used should be written in a consistent style. Later on, on the provider side, Pact uses the uponReceiving description to name the auto-generated test, and the state description is used to find a corresponding test state. // Expected Interaction provider.addInteraction({ state: 'a task with id task-id exists', uponReceiving: 'a request to delete task task-id', withRequest: {method: 'DELETE', path: '/tasks/task-id'}, willRespondWith: {status: 204} }); Paulo Clavijo @pclavijo - January 2018
  • 25. Defining Interactions Examples Successful interaction where data is returned state: ‘tasks for project with id project-id exist’, uponReceiving: ‘a request to get tasks for that project’ Successful interaction where no data is returned state: ‘tasks for project with id project-id do not exist’, uponReceiving: ‘a request to get tasks for that project’ 404 error interaction state: ‘project project-id does not exist’, uponReceiving: ‘a request to get tasks for that project’ Domain validation error interaction state: ‘a task task-id exists and domain rules exist that prevent its modification’, uponReceiving: ‘a request to update that task’ Successful interaction where data is created state: ‘a project with name project-1 does not exist’, uponReceiving: ‘a request to create a project with name project-1’ Paulo Clavijo @pclavijo - January 2018
  • 26. Live Documentation Contracts are not only used by the tests, we also intent them to be user-friendly. Developers can consult contracts in the Pact Broker who shows them in a nice documentation style. Paulo Clavijo @pclavijo - January 2018
  • 27. CDC in our pipeline Paulo Clavijo @pclavijo - January 2018
  • 28. CDC vs Contract Tests TDD is more than having Unit Tests … … CDC is more than having Contract Tests Think in it as Outside-In TDD for a whole system! Is what we do, a technique and attitude, discipline on the design and development flow. Paulo Clavijo @pclavijo - January 2018
  • 29. What is next? ● Pact v3 ○ Contract testing for messages (for services that communicate via event streams and message queues) ● Pact v4 ○ Matching times and dates in a cross-platform manner ○ Additional Matchers ● … Beyond REST APIs. GraphQL? ○ Servers publish a statically typed system specific to their application, and GraphQL provides a unified language to query data within the constraints of that type system. Paulo Clavijo @pclavijo - January 2018
  • 30. Further reading ● Implementing Consumer-Driven Contract tests in Angular, Paulo Clavijo https://paucls.wordpress.com/2017/08/04/pact-consumer-driven-contract-imple mentation-in-angular ● Configure Pact JS Consumer Contract tests in Angular, Paulo Clavijo https://paucls.wordpress.com/2017/08/04/configure-pact-js-consumer-contract- tests-in-angular ● Sample project on Provider Side https://github.com/paucls/task_list_api-kotlin-pact Paulo Clavijo @pclavijo - January 2018
  • 31. References ● ContractTest, Martin Fowler. https://martinfowler.com/bliki/ContractTest.html ● Pact documentation https://docs.pact.io/documentation/implementation_guides.html ● Testing Strategies in a Microservice Architecture, Toby Clemson https://martinfowler.com/articles/microservice-testing/ ● Integrated Tests Are A Scam, J.B. Rainsberger http://blog.thecodewhisperer.com/permalink/integrated-tests-are-a-scam ● Consumer-Driven Contracts: A Service Evolution Pattern, Ian Robinson https://www.martinfowler.com/articles/consumerDrivenContracts.html ● Microservices, Flexible Software Architecture. Eberhard Wolff. ● Contract testing with GraphQL, Andreas Marek https://www.andimarek.com/post/contract-testing-graphql ● https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-junit Paulo Clavijo @pclavijo - January 2018
  • 32. Consumer-Driven Contract Testing Implementing a scalable testing strategy for Microservices Paulo Clavijo Esteban @pclavijo - January 2018