Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Uh, Does This Thing Actually Work? Modern Micro...

Uh, Does This Thing Actually Work? Modern Microservices Testing

To realise the promise of microservices, individual services must be independently deployable, and they should be deployed often. But that’s easier said than done. Releases take confidence.

How does a business achieve enough confidence to release often without getting bogged down in manual QA bottlenecks? Is automating tests too expensive? How do services know if they’ve made a breaking change? If the individual microservices all work, does that mean the system works?

This talk discuss microservices testing strategies and explore some of the modern tools which make testing easier and better. And there’s a demo: Holly will show Pact contract testing, test containers, and Quarkus’s continuous testing and dev services support.

Holly Cummins

June 22, 2023
Tweet

More Decks by Holly Cummins

Other Decks in Programming

Transcript

  1. Disclaimer: I am not a tester. … but that’s ok.

    (Testing is every developer’s job.)
  2. @holly_cummins #RedHat “If your microservice only does one thing, it

    can’t have an error. That would be an additional thing.” – Matt Stratton (not being serious!)
  3. #Quarkus @holly_cummins Netflix microservice architecture “microservices makes testing easy! the

    thing I have to test is so small!” if you only test the points, and not the lines … does the thing work?
  4. @holly_cummins #RedHat “you’re putting a value in the wrong field

    when you call our API. yes, I know there are 15 fields and the names aren’t particularly descriptive.”
  5. @holly_cummins #RedHat TDD: an excellent design tool (if testing is

    hard, that’s a hint the design is wrong)
  6. @holly_cummins #RedHat tools evolve end-to-end tests unit tests integration tests

    low effort high realism tests with application server
  7. @holly_cummins #RedHat tools evolve end-to-end tests unit tests integration tests

    low effort high realism tests with application server test REST endpoints
  8. @holly_cummins #RedHat tools evolve end-to-end tests unit tests integration tests

    low effort high realism tests with application server test REST endpoints
  9. @holly_cummins #RedHat “why have I spent half a day writing

    mocks just so I can write a unit test?” the limitations of unit tests
  10. @holly_cummins #RedHat the limitations of unit tests “why do my

    colleagues tell me my code is broken, even though my unit tests all pass?”
  11. @holly_cummins #RedHat our code our mock our code their actual

    code tests ✔ why mocks aren’t enough
  12. @holly_cummins #RedHat our code our mock our code their actual

    code tests ✔ reality ✘ why mocks aren’t enough
  13. @holly_cummins #RedHat what needs integration tests? our service rest api

    usage by consumers all code that serialises or deserialises data
  14. @holly_cummins #RedHat what needs integration tests? our service rest api

    usage by consumers db calls all code that serialises or deserialises data
  15. @holly_cummins #RedHat what needs integration tests? our service rest api

    usage by consumers db calls queues ETL all code that serialises or deserialises data
  16. @holly_cummins #RedHat what needs integration tests? our service rest api

    usage by consumers db calls filesystem config, etc queues ETL all code that serialises or deserialises data
  17. @holly_cummins #RedHat what needs integration tests? our service rest api

    usage by consumers db calls external applications colleague’s services other services filesystem config, etc queues ETL all code that serialises or deserialises data
  18. @holly_cummins #RedHat what needs integration tests? our service rest api

    usage by consumers db calls external applications colleague’s services filesystem config, etc queues ETL all code that serialises or deserialises data
  19. @holly_cummins #RedHat what needs integration tests? our service rest api

    usage by consumers db calls external applications colleague’s services filesystem config, etc queues ETL all code that serialises or deserialises data
  20. @holly_cummins #RedHat “why do I keep getting failures in production

    even though everything looked fine in staging?” Photo by Eggs&Beer, Flickr
  21. @holly_cummins #RedHat staging staging ✔ why staging is not enough

    our service other services other services other services other services
  22. @holly_cummins #RedHat staging staging ✔ production ✘ why staging is

    not enough our service other services other services other services other services our service production other services other services other services other services
  23. @holly_cummins #RedHat the test trophy end-to-end tests unit tests integration

    tests low effort high realism testing in production
  24. @holly_cummins #RedHat the test trophy end-to-end tests unit tests integration

    tests low effort high realism static tests testing in production
  25. @holly_cummins #RedHat a waste winning confidence effort quality expense hard

    work, but valuable cheap and cheerful unit tests integration tests
  26. @holly_cummins #RedHat a waste winning confidence effort quality expense hard

    work, but valuable cheap and cheerful unit tests integration tests e2e tests
  27. @holly_cummins #RedHat a waste confidence effort quality expense hard work,

    but valuable cheap and cheerful unit tests integration tests e2e tests static tests
  28. @holly_cummins #RedHat a waste confidence effort quality expense hard work,

    but valuable cheap and cheerful unit tests integration tests e2e tests testing in production static tests
  29. @holly_cummins #RedHat a waste confidence effort quality expense hard work,

    but valuable cheap and cheerful unit tests integration tests e2e tests testing in production static tests YMMV
  30. @holly_cummins #RedHat a waste confidence effort quality expense hard work,

    but valuable cheap and cheerful unit tests integration tests e2e tests testing in production static tests YMMV
  31. @holly_cummins #RedHat a waste confidence effort quality expense hard work,

    but valuable cheap and cheerful unit tests integration tests e2e tests testing in production static tests YMMV
  32. @holly_cummins #RedHat a waste confidence effort quality expense hard work,

    but valuable cheap and cheerful unit tests integration tests e2e tests testing in production static tests YMMV
  33. @holly_cummins #RedHat a waste confidence effort quality expense hard work,

    but valuable cheap and cheerful unit tests integration tests e2e tests testing in production static tests
  34. @holly_cummins #RedHat a waste confidence effort quality expense hard work,

    but valuable cheap and cheerful unit tests integration tests e2e tests testing in production static tests constantly question the value of your tests
  35. @holly_cummins #RedHat confidence effort unit tests integration tests e2e tests

    testing in production static tests all integration tests are not created equal
  36. @holly_cummins #RedHat confidence effort unit tests integration tests e2e tests

    testing in production static tests integration tests all integration tests are not created equal
  37. @holly_cummins #RedHat confidence effort unit tests integration tests e2e tests

    testing in production static tests integration tests all integration tests are not created equal integration tests
  38. @holly_cummins #RedHat confidence effort unit tests integration tests e2e tests

    testing in production static tests integration tests all integration tests are not created equal integration tests integration tests
  39. @holly_cummins #RedHat confidence effort unit tests integration tests e2e tests

    testing in production static tests integration tests all integration tests are not created equal integration tests integration tests integration tests
  40. @holly_cummins #RedHat confidence effort unit tests integration tests e2e tests

    testing in production static tests all integration tests are not created equal integration tests contract tests integration tests integration tests
  41. @holly_cummins #RedHat confidence effort unit tests integration tests e2e tests

    testing in production static tests all integration tests are not created equal contract tests sandbox tests integration tests integration tests
  42. @holly_cummins #RedHat confidence effort unit tests integration tests e2e tests

    testing in production static tests all integration tests are not created equal contract tests sandbox tests testcontainers tests integration tests
  43. @holly_cummins #RedHat approaches to integration tests our service rest api

    external applications filesystem colleague’s services colleague’s services colleague’s services external applications
  44. @holly_cummins #RedHat approaches to integration tests our service rest api

    external applications filesystem colleague’s services colleague’s services colleague’s services external applications mock all the things
  45. @holly_cummins #RedHat “why have I spent half a day writing

    mocks just so I can write a cleanly-scoped integration test?”
  46. @holly_cummins #RedHat approaches to integration tests our service rest api

    db calls external applications filesystem config, etc queues ETL colleague’s services colleague’s services colleague’s services external applications
  47. @holly_cummins #RedHat approaches to integration tests our service rest api

    db calls external applications filesystem config, etc queues ETL colleague’s services colleague’s services colleague’s services external applications
  48. @holly_cummins #RedHat approaches to integration tests our service rest api

    db calls external applications filesystem config, etc queues ETL colleague’s services colleague’s services colleague’s services external applications containerise all the things
  49. @holly_cummins #RedHat approaches to integration tests our service rest api

    db calls external applications filesystem config, etc queues ETL colleague’s services colleague’s services colleague’s services external applications containerise all the things
  50. @holly_cummins #RedHat “I can’t bring up my dev stack …

    on my brand new Apple laptop with a M1 chip and 64GB of RAM.” - fintech developer
  51. @holly_cummins #RedHat “I can’t bring up my dev stack …

    on my brand new Apple laptop with a M1 chip and 64GB of RAM.” digression: if this is you • maybe testing is only part of your problem • … and Quarkus could help :) - fintech developer
  52. @holly_cummins #RedHat “I have to do all this shell scripting

    and manual process and orchestration before I can write a test or do development.”
  53. @holly_cummins #RedHat testing is a useful design tool (if testing

    your micro service is hard, that’s a hint the domain boundary is wrong)
  54. @holly_cummins #RedHat approaches to integration tests our service rest api

    external applications filesystem colleague’s services colleague’s services colleague’s services external applications remote sandbox remote system + remote deploy
  55. @holly_cummins #RedHat approaches to integration tests our service rest api

    external applications filesystem colleague’s services colleague’s services colleague’s services external applications remote system with telepresence
  56. @holly_cummins #RedHat approaches to integration tests our service rest api

    external applications filesystem colleague’s services colleague’s services colleague’s services external applications remocal sandbox remote system with telepresence
  57. @holly_cummins #RedHat approaches to integration tests our service rest api

    external applications filesystem colleague’s services colleague’s services colleague’s services external applications remocal sandbox remote system with telepresence
  58. @holly_cummins #RedHat pitfalls: • all services need to be configured

    to forward headers • relies on rest; will not play well with kafka queues or other protocols • can be tricky to get to work
  59. @holly_cummins #RedHat approaches to integration tests our service rest api

    external applications filesystem colleague’s services colleague’s services colleague’s services external applications shared remocal sandbox remote system with telepresence and per-request isolation
  60. @holly_cummins #RedHat pitfalls: • it all works great – until

    a test changes some state, eg • writing to a db • adding a user to a security provider • getting IP whitelists when running locally is tricky
  61. @holly_cummins #RedHat approaches to integration tests our service rest api

    db calls external applications filesystem config, etc queues ETL colleague’s services colleague’s services colleague’s services external applications
  62. @holly_cummins #RedHat approaches to integration tests our service rest api

    db calls external applications filesystem config, etc queues ETL colleague’s services colleague’s services colleague’s services external applications
  63. @holly_cummins #RedHat approaches to integration tests our service rest api

    db calls external applications filesystem config, etc queues ETL colleague’s services colleague’s services colleague’s services external applications testcontainers
  64. @holly_cummins #RedHat approaches to integration tests our service rest api

    db calls external applications filesystem config, etc queues ETL colleague’s services colleague’s services colleague’s services external applications testcontainers
  65. @holly_cummins #RedHat approaches to integration tests our service rest api

    external applications filesystem colleague’s services colleague’s services colleague’s services external applications
  66. @holly_cummins #RedHat approaches to integration tests our service rest api

    external applications filesystem colleague’s services colleague’s services colleague’s services external applications contract test (for services who will talk to you)
  67. @holly_cummins #RedHat our code our mock our code their actual

    code tests ✔ why mocks aren’t enough
  68. @holly_cummins #RedHat our code our mock our code their actual

    code tests ✔ reality ✘ why mocks aren’t enough
  69. @holly_cummins #RedHat our code their code contract test mock functional

    test our tests ✔ their tests ✔ reality ✔ why mocks aren’t enough
  70. @holly_cummins #RedHat our code their code contract test mock functional

    test our tests ✔ their tests ✘ reality ✘ why mocks aren’t enough
  71. @holly_cummins #RedHat our code their code contract test mock functional

    test our tests ✘ their tests ✔ reality ✘ why mocks aren’t enough
  72. #RedHat @holly_cummins demo recap: • consumer-driven contract testing can save

    your bacon • pact is a mock for the consumer • pact is a functional test for the producer • shared json contracts aligns expectations across services
  73. @holly_cummins #RedHat pitfalls of contract testing: • we have to

    talk to the other team • our consumers can break our CI?! • but I’ve already written mocks and functional tests
  74. @holly_cummins #RedHat unexpected benefits of contract testing: preserving backwards compatibility

    YAGNI YAWIBNCSDI* * (you already wrote it but now can safely delete it)
  75. @holly_cummins #RedHat contract testing options: • pact.io • Microcks •

    spring contract • OpenAPI schema validation + mock generation • prism • schemathesis
  76. @holly_cummins #RedHat confidence effort integration testing landscape mock all the

    services testcontainers remote sandbox remocal sandbox contract tests local orchestration
  77. @holly_cummins #RedHat confidence effort integration testing landscape mock all the

    services testcontainers remote sandbox remocal sandbox contract tests local orchestration if you don’t have a big platform team
  78. @holly_cummins #RedHat confidence effort integration testing landscape mock all the

    services testcontainers remote sandbox remocal sandbox contract tests local orchestration if you have a platform team
  79. @holly_cummins #RedHat so, does the thing work? test early, test

    often testcontainers rocks contract testing can prevent pain think both locally and system-level