Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Contract testing. Isolalated testing for microservices
Evgeniy Kuzmin, Alexander Borovets
Smart Gamma
Integration Hell - how to avoid it?
Project V1 - monolith version
- Fuel control / GPS position system
- in-house fuel control hardware
- TomTom GPS position ...
Classic monolith testing
- Stable 3rd party API
- Classic testing requirements and approaches
- Data flows modeling before...
Project’s evolution V2
- New 2nd sub-system for agriculture
- Extendable to 3rd sub-system for industry
- Own data process...
End-2-end testing for data routing feature
- Mock entry point API with emulated flow
- Required etalon data fixtures prelo...
End-2-end testing pros and cons
Trustfull
Create
Execute
Assert
Support
Detect reasons
Testing triangle problem
Integration testing
- Narrow execution area
- Narrow assertion area
Mock testing
- Fast
- Easy to create
- Environment independent
Mock testing problems
- Control mock “expiration”
Mock testing problems
What is a solution?
- Consumer-driven contracts
- Provider-driven contracts
https://docs.pact.io
“Do you set your house on fire
to test your smoke alarm?”
Pact PHP: https://github.com/pact-foundatio...
Each consumer captures their expectations of the provider in a separate contract
Consumer-Driven Contracts
Pact framework
- Pact is contract testing framework
- Contract is a collection of
interactions.
- Each interaction consist...
https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
Pact Response Matchers
https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
Mock server
https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
Result of interaction builder at Pact contract file
https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
Verify interaction on the consumer
Pact on Behat Scenario
PactContext.php src: https://gist.github.com/Evgenas/716fee55126b6e6617f34259a3e2636a
Writing Pact json file locally
Needs to define BROKER_URI
Pact Broker Service
Brocker Web UI
Docker image: https://github.com/DiUS/pact_broker-docker
Browse Pact file
Provider verification
Provider verification
- PACT verifier, and source of contract
- Requests replay
Verify provider - Phpunit test on provider side
Required data on provider
- Needs to define provider state per test case
Required data on provider
Provider state
State API
Given - Pact State(QA API)
Pact State Manager implementation on provider side
Link to github with bundle / implementation
Broker - result of verification
- Сonditions for passing the all test
- Services tested without real interaction
CI / Jenkins - Consumer flow
CI / Jenkins - consumer contract test
CI / Jenkins - trigger downstream provider job
https://gist.github.com/Evgenas/98a1a0f5d2f7665d36e430f687fbf4de
CI / Jenkins - Provider verify contract
CI / Jenkins - Resolve branches for the provider repo
CI / Jenkins - Resolve branches for the provider repo
https://gist.github.com/Evgenas/e9aed2460c7ba24f93c69884df9cc01a
CI / Jenkins - Provider flow
CI / Jenkins - Control backward compatibility by versions and tags
New consumer 1.0.2 changed schema expectation
New provi...
https://gist.github.com/Evgenas/61ac7b6efb999896df9017194158cb4c
CI / Jenkins - deploy “can-i-deploy”
PACT Broker client: https://github.com/pact-foundation/pact_broker-client#can-i-deploy
evgeniy.k@smart-gamma.com
https://www.linkedin.com/in/evgeniy-kuzmin-03816a52/
Contract testing - isolated testing of microservices - Symfony Camp 2018, Evgeniy Kuzmin, Alexander Borovets, Smart Gamma
Nächste SlideShare
Wird geladen in …5
×

Contract testing - isolated testing of microservices - Symfony Camp 2018, Evgeniy Kuzmin, Alexander Borovets, Smart Gamma

104 Aufrufe

Veröffentlicht am

Smart Gamma team will talk In this speech about the problems that arise when testing applications built on a microservices architecture. We will conduct a brief overview of how to test the interaction between microservices. We will also talk in details about Consumer Driven Contract Testing with an example of using the pact.io tool.

Veröffentlicht in: Ingenieurwesen

Contract testing - isolated testing of microservices - Symfony Camp 2018, Evgeniy Kuzmin, Alexander Borovets, Smart Gamma

  1. 1. Contract testing. Isolalated testing for microservices Evgeniy Kuzmin, Alexander Borovets Smart Gamma
  2. 2. Integration Hell - how to avoid it?
  3. 3. Project V1 - monolith version - Fuel control / GPS position system - in-house fuel control hardware - TomTom GPS position system as data gateway - Monolith architecture for data processing via WebFleet API - UI customers area
  4. 4. Classic monolith testing - Stable 3rd party API - Classic testing requirements and approaches - Data flows modeling before hardware is functional
  5. 5. Project’s evolution V2 - New 2nd sub-system for agriculture - Extendable to 3rd sub-system for industry - Own data processing system via GSM instead of TomTom - Universal hardware for all sub- systems - Hardware shop
  6. 6. End-2-end testing for data routing feature - Mock entry point API with emulated flow - Required etalon data fixtures preload or setup via QA API - Setup test infrastructure with all services deployed - Execute test - Assert all expected behavior
  7. 7. End-2-end testing pros and cons Trustfull Create Execute Assert Support Detect reasons
  8. 8. Testing triangle problem
  9. 9. Integration testing - Narrow execution area - Narrow assertion area
  10. 10. Mock testing - Fast - Easy to create - Environment independent
  11. 11. Mock testing problems - Control mock “expiration”
  12. 12. Mock testing problems
  13. 13. What is a solution? - Consumer-driven contracts - Provider-driven contracts
  14. 14. https://docs.pact.io “Do you set your house on fire to test your smoke alarm?” Pact PHP: https://github.com/pact-foundation/pact-php
  15. 15. Each consumer captures their expectations of the provider in a separate contract Consumer-Driven Contracts
  16. 16. Pact framework - Pact is contract testing framework - Contract is a collection of interactions. - Each interaction consist of expected request and minimal expected response.
  17. 17. https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
  18. 18. https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
  19. 19. Pact Response Matchers
  20. 20. https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
  21. 21. Mock server
  22. 22. https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
  23. 23. Result of interaction builder at Pact contract file
  24. 24. https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
  25. 25. https://gist.github.com/Evgenas/ef21e19cfa894507d091985c45bddf12
  26. 26. Verify interaction on the consumer
  27. 27. Pact on Behat Scenario PactContext.php src: https://gist.github.com/Evgenas/716fee55126b6e6617f34259a3e2636a
  28. 28. Writing Pact json file locally
  29. 29. Needs to define BROKER_URI
  30. 30. Pact Broker Service
  31. 31. Brocker Web UI Docker image: https://github.com/DiUS/pact_broker-docker
  32. 32. Browse Pact file
  33. 33. Provider verification
  34. 34. Provider verification - PACT verifier, and source of contract - Requests replay
  35. 35. Verify provider - Phpunit test on provider side
  36. 36. Required data on provider - Needs to define provider state per test case
  37. 37. Required data on provider
  38. 38. Provider state State API
  39. 39. Given - Pact State(QA API)
  40. 40. Pact State Manager implementation on provider side Link to github with bundle / implementation
  41. 41. Broker - result of verification - Сonditions for passing the all test - Services tested without real interaction
  42. 42. CI / Jenkins - Consumer flow
  43. 43. CI / Jenkins - consumer contract test
  44. 44. CI / Jenkins - trigger downstream provider job https://gist.github.com/Evgenas/98a1a0f5d2f7665d36e430f687fbf4de
  45. 45. CI / Jenkins - Provider verify contract
  46. 46. CI / Jenkins - Resolve branches for the provider repo
  47. 47. CI / Jenkins - Resolve branches for the provider repo https://gist.github.com/Evgenas/e9aed2460c7ba24f93c69884df9cc01a
  48. 48. CI / Jenkins - Provider flow
  49. 49. CI / Jenkins - Control backward compatibility by versions and tags New consumer 1.0.2 changed schema expectation New provider 1.0.2 changed provided schema Provider 1.0.2 and Consumer 1.0.2 should be deployed simultaneously only!
  50. 50. https://gist.github.com/Evgenas/61ac7b6efb999896df9017194158cb4c
  51. 51. CI / Jenkins - deploy “can-i-deploy” PACT Broker client: https://github.com/pact-foundation/pact_broker-client#can-i-deploy
  52. 52. evgeniy.k@smart-gamma.com https://www.linkedin.com/in/evgeniy-kuzmin-03816a52/

×