Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Marcin Grzejszczak - Contract Tests in the Enterprise

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio

Eche un vistazo a continuación

1 de 90 Anuncio

Marcin Grzejszczak - Contract Tests in the Enterprise

Descargar para leer sin conexión

Is your legacy application talking to a service that is never up and running on your shared testing environment? Does your company waste a lot of time and money on regression testing only to see that, yet again, someone has created a typo in the API? Enough is enough. Time to fix this problem using contract tests!

In this presentation you’ll see how to migrate a legacy application to work with stubs of external applications. We’ll show different ways of increasing your test reliability by writing adding contract tests of your API. You’ll see the difference between producer and consumer driven contracts.

Is your legacy application talking to a service that is never up and running on your shared testing environment? Does your company waste a lot of time and money on regression testing only to see that, yet again, someone has created a typo in the API? Enough is enough. Time to fix this problem using contract tests!

In this presentation you’ll see how to migrate a legacy application to work with stubs of external applications. We’ll show different ways of increasing your test reliability by writing adding contract tests of your API. You’ll see the difference between producer and consumer driven contracts.

Anuncio
Anuncio

Más Contenido Relacionado

Similares a Marcin Grzejszczak - Contract Tests in the Enterprise (20)

Anuncio

Más de SegFaultConf (9)

Más reciente (20)

Anuncio

Marcin Grzejszczak - Contract Tests in the Enterprise

  1. 1. 1 © 2018 Pivotal Contract Tests in the Enterprise Marcin Grzejszczak, @mgrzejszczak
  2. 2. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ About me Spring Cloud developer at Pivotal working mostly on ● Spring Cloud Sleuth ● Spring Cloud Contract ● Spring Cloud Pipelines Connect with me ● Twitter: @mgrzejszczak ● Blog: http://toomuchcoding.com 2
  3. 3. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ #frameworkless #backtothebasics 3
  4. 4. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Just another day at work 4 http://4.bp.blogspot.com/-6OK2CgfysNQ/U86JhcS_OKI/AAAAAAAAurI/O5lNezASrwo/s1600/10373729_294545550713169_1314239177487458186_n.jpg
  5. 5. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How the code is currently organized 5
  6. 6. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How our CI system looks like 6 https://images.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.findbestopensource.com% 2FAppImages%2FArticle%2Fjenkins-img1.jpg&f=1
  7. 7. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How the code is currently deployed 7 https://www.process.st/business-process-modeling/ 15 HOURS OF E2E TESTS PLACE HERE
  8. 8. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ We’re agile & we care about quality 8 THE SPRINT (6 MONTHS) 5 MONTHSLAST MONTH
  9. 9. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Application Architecture 9 Legacy service Customer Rental History service Payment processor Mainframe Audit service Insurance service ● Interservice calls are over http ● Legacy service that is hard to test due the dependencies it has on other downstream services
  10. 10. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s our testing strategy? 10
  11. 11. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How the code is currently tested 11 https://www.ontestautomation.com/wp-content/uploads/2014/06/pyramid_inverted.png MANUAL TESTING
  12. 12. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The testing pyramid... 12
  13. 13. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Unit Test In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules (...) are tested to determine whether they are fit for use. 13 Kolawa, Adam; Huizinga, Dorota (2007). Automated Defect Prevention: Best Practices in Software Management. Wiley-IEEE Computer Society Press. p. 75. ISBN 0-470-04212-5.
  14. 14. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Great! I’ll write unit tests only! 14
  15. 15. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Unit tests FTW! 15
  16. 16. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Integration Test Integration testing (...) is the phase in software testing in which individual software modules are combined and tested as a group. (...) Integration testing takes as its input modules that have been unit tested, groups them in larger aggregates, applies tests (...) and delivers as its output the integrated system ready for system testing 16 Martyn A Ould & Charles Unwin (ed), Testing in Software Development, BCS (1986), p71.
  17. 17. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Ok I don’t need unit tests, I’ll write only integration tests 17
  18. 18. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Integration tests FTW! 18
  19. 19. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 19
  20. 20. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ End to end Test End-to-end testing involves ensuring that the integrated components of an application function as expected. The entire application is tested in a real-world scenario such as communicating with the database, network, hardware and other applications. 20 https://www.techopedia.com/definition/7035/end-to-end-test
  21. 21. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ End to end tests FTW! 21 https://www.process.st/business-process-modeling/ 15 HOURS OF E2E TESTS PLACE HERE
  22. 22. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ End to end tests FTW! 22
  23. 23. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Speaking of End to End tests… The Customer Rental History is unreliable 23
  24. 24. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Application Architecture 24 Legacy service Customer Rental History service Payment processor Mainframe Audit service Insurance service
  25. 25. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Testing Strategy - Hard Coded Object Stubs 25 Legacy service Customer Rental History service Payment processor Audit service Insurance service Hard coded Customer Rental History Service Stub Mainframe
  26. 26. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Problems with hard coding stubs 26 ● 1225 line JSON response ● Hard to keep hard coded stub in sync with the api being stubbed ● Stub does not test that requests are made correctly to the remote service
  27. 27. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Problems with hard coding stubs 27 Stubs that were used in the build phase have nothing to do with the real API!! /foo LEGACY APP CUSTOMER RENTAL HISTORY TEST OK /foo LEGACY APP CUSTOMER RENTAL HISTORY REALITY WAT?! If /foo respond with OK
  28. 28. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How to create reliable stubs for services we don’t control? 28
  29. 29. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Let’s proxy the calls! 29
  30. 30. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Generating Stubs From Proxy 30 Test that calls Customer Rental History Service Customer Rental History Service Payment processor Mainframe PROXY Record traffic and dump stubs (e.g. once per day) Upload stubs for other teams to use
  31. 31. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Stubs From Proxy 31 Given this request Send back this response
  32. 32. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Now that we have stubs, how can we test the system? 32
  33. 33. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Testing Strategy - Generated Remote Stub 33 Legacy service Customer Rental History Service Payment processor Customer Rental History Service Stub from the proxy Legacy service integration test Mainframe
  34. 34. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outcome? Fast feedback from quite reliable stubs Less money spent on e2e 34
  35. 35. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ OK, we’ve dealt with the app we don’t control. How about those we do control? 35
  36. 36. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hard Problems ● How can something be added to a service without breaking the clients? ● How can something be removed from a service without breaking the clients? ● How can a service developer find out how clients are using their service? ● How to enable short release cycles and continuous delivery of services? 36
  37. 37. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Service Evolution Patterns ● Tolerant Reader ○ Extract only what is needed, ignore unknown content ● Schema Versioning ○ Put Schema versions in the API url / headers (v1, v2) ● Extension Points ○ Additional, optional data structured in a predefined extension field ● Consumer-Driven Contracts 37 http://servicedesignpatterns.com/WebServiceEvolution
  38. 38. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Definitions ● Producer ○ service that exposes an API / sends a message ● Consumer ○ service that consumes the API of the producer / listens to a message from the producer ● Contract ○ agreement between producer and consumer how the API / message will look like 38
  39. 39. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Provider Contract • The implementer of a service defines the interface of the service everyone uses the same interface 39 Service Client A Client B
  40. 40. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consumer Contract ● The consumer of a service defines their interface to the service within the conventions / spirit of provider contract 40 Service Client A Client B
  41. 41. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consumer Driven Contracts 41 Source: http://martinfowler.com/articles/consumerDrivenContracts.html
  42. 42. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Benefits of Consumer Driven Contracts ● Align service providers with the business goals of their consumer through the consumer driven contracts ● Provide insights into how a service is being used by its consumers ● Make evolving services easier by reducing the amount of coordination required to evolve interfaces ● Help in the configuration of continuous delivery pipelines 42
  43. 43. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How the code should be tested 43 UNIT TESTS SERVICE, API, CONTRACT TESTS E2E, UI TESTS MANUAL TESTS MANUAL TESTING
  44. 44. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Migrating to microservices... 44
  45. 45. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Problem? Our monolith is the source of truth We don’t know if we can change its API 45
  46. 46. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Monolith as source of truth 46 Legacy service Audit service Insurance service Ledger service Payment service Invoice service Warehouse service
  47. 47. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ GET /user/GET /user/ Consumers create stubs (current approach) 47 Legacy service GET /user/Audit service Insurance service Ledger service Payment service Invoice service Warehouse service GET /user/
  48. 48. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Problem? Stubs on the consumer side not reliable Time wasted on writing the same stubs 48
  49. 49. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Let’s write a Segfault Contract contract testing framework! #frameworkless 49
  50. 50. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ We need to define a contract somehow 50
  51. 51. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Example of a contract 51 Given this request Send back this response
  52. 52. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ We need to assert that contract is valid We want to build reliable stubs 52
  53. 53. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Stubs Generating Stubs & Tests (PRODUCER) 53 Legacy service Customer Rental History Service Payment processor Mainframe Audit service Insurance service Contract Tests
  54. 54. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Generating Stubs & Tests (PRODUCER) 54 Generate reusable stubs Read Run tests to verify if contract is met Run build $ build project
  55. 55. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Contract Tests (PRODUCER) 55 Given this request Is the response correct ? Send the request
  56. 56. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Generated Stubs (PRODUCER) 56 Given this request Send back this response
  57. 57. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Monolith as source of truth (better approach) 57 GET /user/ Legacy service POST /user/ Audit service Insurance service Ledger service Payment service Invoice service Warehouse service STUB STORAGE
  58. 58. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reuse Stubs (CONSUMER) 58 Fetch stubs & run stub servers Consumer tests Test runner Fetch stubs STUB STORAGE
  59. 59. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Outcome? Fast feedback from reliable stubs (fail fast) Less money spent on e2e Less time wasted on duplicating stubs 59
  60. 60. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ OK, what about new, shiny microservices? 60
  61. 61. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Nice API creation ● It’s the consumer that uses the API ● Consumers should take part in the creation of the API of the producer ● The producer’s API change should be driven by consumers 61
  62. 62. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consumer Driven Contracts 62
  63. 63. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ There is no producer code! 63 CONSUMER REPO WITH CONTRACTS INTERACTION I THINK I LIKE THIS API EVEN THOUGH THE PRODUCER DOESN’T EVEN EXIST! WHAT IF I CALLED THE API LIKE THIS...
  64. 64. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Store the stubs from contracts locally 64 CONSUMER REPO WITH CONTRACTS INTERACTION LOCAL STORAGE WITH STUBS
  65. 65. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Play with the API offline 65 CONSUMER REPO WITH CONTRACTS TESTS LOCAL STORAGE WITH STUBS FROM
  66. 66. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ File a PR 66 CONSUMER REPO WITH CONTRACTS YUP, I LIKE IT! TIME FOR A PR PR
  67. 67. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Producer sets up a project 67 PRODUCER REPO WITH CONTRACTS INTRACTION OH, SOMEONE HAS REQUESTED THAT I HAVE SUCH API...
  68. 68. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Producer sets up a project 68 PRODUCER REPO WITH CONTRACTS INTRACTION THE TESTS ARE FAILING… NO WONDER, I HAVE NO CODE :|
  69. 69. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Producer makes the generated tests pass 69 PRODUCER REPO WITH CONTRACTS PR OK, THE TESTS ARE PASSING, LET ME MERGE THE PR TO MASTER
  70. 70. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ CI server builds the producer code 70 PRODUCER BUILD UPLOAD BINARY UPLOAD STUBS STUB STORAGE BINARY STORAGE CI SYSTEM
  71. 71. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Consumer uses uploaded stubs 71 CONSUMER LET ME USE THE PRODUCER’S STUBS FOR MY TESTS FETCHSTUBS STUB STORAGE
  72. 72. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Did you say, that ALL contracts are stored in a single repo? 72
  73. 73. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 73
  74. 74. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 74
  75. 75. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 75
  76. 76. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 76
  77. 77. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What about messaging? 77
  78. 78. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 78 CONSUMERPRODUCER TEST PRODUCER CONSUMER REALITY topic: bar topic: foo topic: bartopic: foo
  79. 79. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Messaging 79 (PRODUCER) Do I trigger the message? (PRODUCER) Is it sent to a proper destination? (PRODUCER) Can I serialize it properly? (CONSUMER) Do I listen at a proper destination? (CONSUMER) Can I deserialize it properly?
  80. 80. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What about polyglot support? 80
  81. 81. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ NodeJs app 81 https://github.com/marcingrzejszczak/sc-contract-car-rental NodeJs Some HTTP service
  82. 82. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Doesn’t work 82
  83. 83. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Polyglot 83 Non JVM app Send a request Stub will respond RUN STUB STORAGE
  84. 84. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ NodeJs works 84
  85. 85. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Can I generate tests for an app in any language? 85
  86. 86. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Polyglot 86 contract1.yml GET /user/ App contract2.yml POST /user/ Contracts mounted to generate tests and stubs Tests executed from the container against a running app RUN STUB STORAGE
  87. 87. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 87
  88. 88. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ● The implemented framework: Spring Cloud Contract ● The stub server: WireMock ● Available DSLs: Groovy, YAML ● Supports: ○ messaging (Spring Cloud Stream, Spring Integration, Spring AMQP, whatever you want) ○ dynamic pieces ○ resolution of request from response ○ stateful stubs (stubs have memory) ○ you can store stubs in Git, Nexus / Artifactory, Pact Broker ● And much, much more… ● Read the docs: http://cloud.spring.io/spring-cloud-contract/ What have we managed to build? 88 #frameworkless
  89. 89. Unless otherwise indicated, these slides are © 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Disclaimer Statement 89
  90. 90. mgrzejszczak

×