SlideShare a Scribd company logo
1 of 33
Download to read offline
Consumer Driven Contract
Max Danylenko
About me
● I love surfing and other physical activities
● I became a father 5 months ago
● For Some of you I am direct manager
User service
User service
{
"id": 1,
"name": "Mike",
"age": 24
}
How I can test the User Service API?
User service
{
"id": 1,
"name": "Mike",
"age": 24
}
Integration tests
User service
Test client
New terminology: Producer and Consumer
User service
UI service
Consumer Producer
service that exposes a resource
End-to-end tests
User service
Test client
The most natural approach to testing API is end-to-end testing. In
end-to-end tests (E2E tests), real servers or containers are set up so
all other services they require as dependencies, such as databases
are available in a production-like runtime environment.
To execute our integration tests, the test client is calls the Service and
the test asserts (again in the UI) if the results meet the expectations
defined.
UI
New requirement about user name comes
User service
{
"id": 1,
"name": "James",
"age": 24,
"firstName": "James",
"secondName": "May"
}
New requirement about user name comes
User service
Test client UI
Refactored and test here
Fix tests here
User service affect some services on PROD
Real situation
User service
Age validation UI New Service
{
"id": 1,
"name": "James",
"age": 24
}
{
"id": 1,
"name": "James",
"age": 24
}
{
"id": 1,
"name": "James",
"age": 24,
"firstName": "James",
"secondName": "May"
}
Consumers
Producer
User service
Age validation UI New Service
{
"id": 1,
"name": "James",
"age": 24
}
{
"id": 1,
"name": "James",
"age": 24
}
{
"id": 1,
"name": "James",
"age": 24,
"firstName": "James",
"secondName": "May"
}
Consumers
Producer
User service
Age validation UI
{
"id": 1,
"name": "James",
"age": 24
}
{
"id": 1,
"name": "James",
"age": 24
}
Consumers
Producer
How we can avoid this situation?
Just add piece of integration tests
User service
Age validation
UI
New Service
Test client
Could you help small test client verify all services
Test client
What kind of test we can write?
Mock
In a mock test, we no longer set up
a whole runtime environment, but
run isolated tests between the
consumer and a mock provider and
between a mock consumer and the
real provider
Consumer-Driven Contract Tests
Consumer-Driven Contract
tests (CDC tests) are a
specialization of mock tests as
described above. They work
just like mock tests with the
specialty that the interface
contract is driven by the
consumer and not, as one
would expect naturally, by the
provider. This provides some
interesting advantages we will
come to later
Contracts
User service
Age validation UI New Service
{
"id": 1,
"name": "James",
"age": 24
}
{
"id": 1,
"name": "James",
"age": 24
}
{
"id": 1,
"name": "James",
"age": 24,
"firstName": "James",
"secondName": "May"
}
Consumers
Producer
Contract Contract Contract
By receiving contract test suites from all
consumers of a service, it is possible to
make changes to that service safe in the
knowledge that consumers won't be
impacted
E2E vs Mock vs Consumer-driven contract
● Isolation
● Complexity
● Test Data Setup
● Testing Data Semantics
● Feedback Time
● Stability
● Reveal Unused Interfaces
● Well-Fittedness
Isolation
isolated tests are easy to
execute and their results are
easy to interpret, thus we
should rely on them as long as
it’s possible.
E2E Mock CDC
Isolation
Complexity: For an E2E runtime
environment, we
have to deploy
containers running
your services, their
databases and any
other dependencies
they might have,
each in a specified
versions
E2E Mock CDC
Complexity
Test Data Setup:
Test data is always an issue when
implementing tests of any sort. In E2E tests
test data is especially troublesome since you
have potentially many services each with their
own database (see image in the previous
section). To set up a test environment for those
E2E tests you have to provide each of those
databases with test data that match the
expectations of your tests.
E2E Mock CDC
Test data setup
Testing Data Semantics
The correct semantics of data
exchanged over an interface are,
naturally, important for the data to
be processed correctly. However,
mock tests usually only check the
syntax of the data, e.g. if a user
data is syntactically correct but not
if a user not exist .
E2E Mock CDC
Testing data semantics
Feedback Time
Another important issue in testing is the time it takes from starting
your tests until you get the results and can act on them by fixing a
bug or modifying a test. The shorter this feedback time, the more
productive you can be.
Due to their integrative nature, E2E tests usually have a rather long
feedback time. One cause for this is the time it takes to set up a
complete E2E runtime environment. The other cause is that once
you have set up that environment you probably won’t just run a
single test but rather a complete suite of tests, which tends to take
some time.
E2E Mock CDC
Feedback time
Stability
Unstable tests lead to dangerous mindsets like
“A couple tests failed, but 90% successfull tests
are OK, so let’s deploy to production.”.
E2E Mock CDC
Stability
Reveal Unused Interfaces
E2E Mock CDC
Reveal Unused Interfaces
The provider does not really
know which operations of its
API are used by which
consumer. This may lead to a
situation where an operation
of the API is not used by any
consumer.
Well-Fittedness
E2E Mock CDC
Well-Fittedness
A very similar issue is the
issue of well-fittedness of the
API operations for a certain
consumer. If a provider
dictates an API contract, it
may not fit certain use cases
of certain consumers
optimally. If the consumer
defines the contract, it may be
defined to fit its use case
better
Results:
E2E Mock CDC
Isolation - + +
Complexity - + +
Test data setup - + +
Testing Data Semantics + - +
Feedback Time - + +
Stability - + +
Reveal Unused Interfaces +- - +
Well-Fittedness +- - +
What is next?
Who can help with PoC?
Thanks

More Related Content

Similar to Consumer Driven Contract.pdf

Performance Test Slideshow Recent
Performance Test Slideshow RecentPerformance Test Slideshow Recent
Performance Test Slideshow Recent
Future Simmons
 
Performance Test Slideshow R E C E N T
Performance Test Slideshow R E C E N TPerformance Test Slideshow R E C E N T
Performance Test Slideshow R E C E N T
Future Simmons
 
Testing Software Solutions
Testing Software SolutionsTesting Software Solutions
Testing Software Solutions
gavhays
 
Resumeupdated
ResumeupdatedResumeupdated
Resumeupdated
sudha A
 

Similar to Consumer Driven Contract.pdf (20)

Introduce Test Harness for Direct To Consumer Solutions.pdf
Introduce Test Harness for Direct To Consumer Solutions.pdfIntroduce Test Harness for Direct To Consumer Solutions.pdf
Introduce Test Harness for Direct To Consumer Solutions.pdf
 
User Acceptance Testing Services
User Acceptance Testing ServicesUser Acceptance Testing Services
User Acceptance Testing Services
 
Performance Test Slideshow Recent
Performance Test Slideshow RecentPerformance Test Slideshow Recent
Performance Test Slideshow Recent
 
Performance Test Slideshow R E C E N T
Performance Test Slideshow R E C E N TPerformance Test Slideshow R E C E N T
Performance Test Slideshow R E C E N T
 
Future of QA
Future of QAFuture of QA
Future of QA
 
Futureofqa
FutureofqaFutureofqa
Futureofqa
 
A STUDY OF FORMULATION OF SOFTWARE TEST METRICS FOR INTERNET BASED APPLICATIONS
A STUDY OF FORMULATION OF SOFTWARE TEST METRICS FOR INTERNET BASED APPLICATIONSA STUDY OF FORMULATION OF SOFTWARE TEST METRICS FOR INTERNET BASED APPLICATIONS
A STUDY OF FORMULATION OF SOFTWARE TEST METRICS FOR INTERNET BASED APPLICATIONS
 
FROM THE ART OF SOFTWARE TESTING TO TEST-AS-A-SERVICE IN CLOUD COMPUTING
FROM THE ART OF SOFTWARE TESTING TO TEST-AS-A-SERVICE IN CLOUD COMPUTINGFROM THE ART OF SOFTWARE TESTING TO TEST-AS-A-SERVICE IN CLOUD COMPUTING
FROM THE ART OF SOFTWARE TESTING TO TEST-AS-A-SERVICE IN CLOUD COMPUTING
 
From the Art of Software Testing to Test-as-a-Service in Cloud Computing
From the Art of Software Testing to Test-as-a-Service in Cloud ComputingFrom the Art of Software Testing to Test-as-a-Service in Cloud Computing
From the Art of Software Testing to Test-as-a-Service in Cloud Computing
 
A Comprehensive Guide to Accelerate and Strengthen Your End-to-End Testing Ap...
A Comprehensive Guide to Accelerate and Strengthen Your End-to-End Testing Ap...A Comprehensive Guide to Accelerate and Strengthen Your End-to-End Testing Ap...
A Comprehensive Guide to Accelerate and Strengthen Your End-to-End Testing Ap...
 
CLOUD TESTING MODEL – BENEFITS, LIMITATIONS AND CHALLENGES
CLOUD TESTING MODEL – BENEFITS, LIMITATIONS AND CHALLENGESCLOUD TESTING MODEL – BENEFITS, LIMITATIONS AND CHALLENGES
CLOUD TESTING MODEL – BENEFITS, LIMITATIONS AND CHALLENGES
 
Testing Software Solutions
Testing Software SolutionsTesting Software Solutions
Testing Software Solutions
 
Fundamentals of software testing
Fundamentals of software testingFundamentals of software testing
Fundamentals of software testing
 
An introduction to Software Testing and Test Management
An introduction to Software Testing and Test ManagementAn introduction to Software Testing and Test Management
An introduction to Software Testing and Test Management
 
Resumeupdated
ResumeupdatedResumeupdated
Resumeupdated
 
Industrial Training in Software Testing
Industrial Training in Software TestingIndustrial Training in Software Testing
Industrial Training in Software Testing
 
Myths and reality about software testing
Myths and reality about software testingMyths and reality about software testing
Myths and reality about software testing
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Test plan
Test planTest plan
Test plan
 
Making the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To TestingMaking the Unstable Stable - An Intro To Testing
Making the Unstable Stable - An Intro To Testing
 

More from Danylenko Max (6)

How to write clean tests
How to write clean testsHow to write clean tests
How to write clean tests
 
Consumer driven contract
Consumer driven contractConsumer driven contract
Consumer driven contract
 
Fail fast! approach
Fail fast! approachFail fast! approach
Fail fast! approach
 
Monitoring and observability
Monitoring and observabilityMonitoring and observability
Monitoring and observability
 
How to successfully grow a code review culture
How to successfullygrow a code review cultureHow to successfullygrow a code review culture
How to successfully grow a code review culture
 
Testing microservices
Testing microservicesTesting microservices
Testing microservices
 

Recently uploaded

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Recently uploaded (20)

%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 

Consumer Driven Contract.pdf

  • 2. About me ● I love surfing and other physical activities ● I became a father 5 months ago ● For Some of you I am direct manager
  • 3. User service User service { "id": 1, "name": "Mike", "age": 24 }
  • 4. How I can test the User Service API? User service { "id": 1, "name": "Mike", "age": 24 }
  • 6. New terminology: Producer and Consumer User service UI service Consumer Producer service that exposes a resource
  • 7. End-to-end tests User service Test client The most natural approach to testing API is end-to-end testing. In end-to-end tests (E2E tests), real servers or containers are set up so all other services they require as dependencies, such as databases are available in a production-like runtime environment. To execute our integration tests, the test client is calls the Service and the test asserts (again in the UI) if the results meet the expectations defined. UI
  • 8. New requirement about user name comes User service { "id": 1, "name": "James", "age": 24, "firstName": "James", "secondName": "May" }
  • 9. New requirement about user name comes User service Test client UI Refactored and test here Fix tests here
  • 10. User service affect some services on PROD
  • 11. Real situation User service Age validation UI New Service { "id": 1, "name": "James", "age": 24 } { "id": 1, "name": "James", "age": 24 } { "id": 1, "name": "James", "age": 24, "firstName": "James", "secondName": "May" } Consumers Producer
  • 12. User service Age validation UI New Service { "id": 1, "name": "James", "age": 24 } { "id": 1, "name": "James", "age": 24 } { "id": 1, "name": "James", "age": 24, "firstName": "James", "secondName": "May" } Consumers Producer
  • 13. User service Age validation UI { "id": 1, "name": "James", "age": 24 } { "id": 1, "name": "James", "age": 24 } Consumers Producer
  • 14. How we can avoid this situation?
  • 15. Just add piece of integration tests User service Age validation UI New Service Test client
  • 16. Could you help small test client verify all services Test client
  • 17. What kind of test we can write?
  • 18. Mock In a mock test, we no longer set up a whole runtime environment, but run isolated tests between the consumer and a mock provider and between a mock consumer and the real provider
  • 19. Consumer-Driven Contract Tests Consumer-Driven Contract tests (CDC tests) are a specialization of mock tests as described above. They work just like mock tests with the specialty that the interface contract is driven by the consumer and not, as one would expect naturally, by the provider. This provides some interesting advantages we will come to later
  • 20. Contracts User service Age validation UI New Service { "id": 1, "name": "James", "age": 24 } { "id": 1, "name": "James", "age": 24 } { "id": 1, "name": "James", "age": 24, "firstName": "James", "secondName": "May" } Consumers Producer Contract Contract Contract By receiving contract test suites from all consumers of a service, it is possible to make changes to that service safe in the knowledge that consumers won't be impacted
  • 21. E2E vs Mock vs Consumer-driven contract ● Isolation ● Complexity ● Test Data Setup ● Testing Data Semantics ● Feedback Time ● Stability ● Reveal Unused Interfaces ● Well-Fittedness
  • 22. Isolation isolated tests are easy to execute and their results are easy to interpret, thus we should rely on them as long as it’s possible. E2E Mock CDC Isolation
  • 23. Complexity: For an E2E runtime environment, we have to deploy containers running your services, their databases and any other dependencies they might have, each in a specified versions E2E Mock CDC Complexity
  • 24. Test Data Setup: Test data is always an issue when implementing tests of any sort. In E2E tests test data is especially troublesome since you have potentially many services each with their own database (see image in the previous section). To set up a test environment for those E2E tests you have to provide each of those databases with test data that match the expectations of your tests. E2E Mock CDC Test data setup
  • 25. Testing Data Semantics The correct semantics of data exchanged over an interface are, naturally, important for the data to be processed correctly. However, mock tests usually only check the syntax of the data, e.g. if a user data is syntactically correct but not if a user not exist . E2E Mock CDC Testing data semantics
  • 26. Feedback Time Another important issue in testing is the time it takes from starting your tests until you get the results and can act on them by fixing a bug or modifying a test. The shorter this feedback time, the more productive you can be. Due to their integrative nature, E2E tests usually have a rather long feedback time. One cause for this is the time it takes to set up a complete E2E runtime environment. The other cause is that once you have set up that environment you probably won’t just run a single test but rather a complete suite of tests, which tends to take some time. E2E Mock CDC Feedback time
  • 27. Stability Unstable tests lead to dangerous mindsets like “A couple tests failed, but 90% successfull tests are OK, so let’s deploy to production.”. E2E Mock CDC Stability
  • 28. Reveal Unused Interfaces E2E Mock CDC Reveal Unused Interfaces The provider does not really know which operations of its API are used by which consumer. This may lead to a situation where an operation of the API is not used by any consumer.
  • 29. Well-Fittedness E2E Mock CDC Well-Fittedness A very similar issue is the issue of well-fittedness of the API operations for a certain consumer. If a provider dictates an API contract, it may not fit certain use cases of certain consumers optimally. If the consumer defines the contract, it may be defined to fit its use case better
  • 30. Results: E2E Mock CDC Isolation - + + Complexity - + + Test data setup - + + Testing Data Semantics + - + Feedback Time - + + Stability - + + Reveal Unused Interfaces +- - + Well-Fittedness +- - +
  • 32. Who can help with PoC?