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

7-11-23 - [RivieraDev] - Avoiding Common Pitfal...

7-11-23 - [RivieraDev] - Avoiding Common Pitfalls with Modern Microservices Testing

Have you ever wondered why your microservices break in production after all the tests have passed during CI/CD? Have you ever wondered if you’re testing too much or too little? If you want to learn about common pitfalls and how to catch them at build time rather than at runtime, this session is for you!

In this session, I’ll share some common battle scars from my experiences in the field. Additionally, I will introduce the testing pyramid and explain why it is important in helping to continuously deploy microservices independently without fear. I will demonstrate, through a test-driven development approach, how the combination of Pact contract testing combined with Quarkus developer joy can help prevent your microservices from breaking in production.

Eric Deandrea

July 10, 2023
Tweet

More Decks by Eric Deandrea

Other Decks in Technology

Transcript

  1. Eric Deandrea Sr. Principal Developer Advocate Red Hat @edeandrea Avoiding

    common pitfalls with modern microservices testing Drawings courtesy of Holly Cummins
  2. @edeandrea #RedHat #RivieraDev2023 Disclaimer! I am not a tester. (or

    even test expert) That’s ok– testing is every developer’s job!
  3. @edeandrea #RedHat #RivieraDev2023 Netflix microservice architecture Testing with microservices is

    easy! My services are so small! Everything is decoupled! But….. If you only test the points, And not the lines…. Does the thing actually work?
  4. @edeandrea #RedHat #RivieraDev2023 “It is all that is left unsaid

    upon which tragedies are built.” - Kreia, Star Wars Knights of the Old Republic II: The Sith Lords
  5. @edeandrea #RedHat #RivieraDev2023 “You lied to me. How many other

    lies have I been told by the Council? And how do you know that you even have the truth?” – Anakin Skywalker
  6. @edeandrea #RedHat #RivieraDev2023 “Many of the truths that we cling

    to depend on our viewpoint.” — Obi-Wan Kenobi, Return of the Jedi
  7. end-to-end tests unit tests integration tests low effort high realism

    tests with application server test REST endpoints tests with a database
  8. @edeandrea #RedHat #RivieraDev2023 our mock our code ✔ tests ✘

    reality our code their actual code Why mocks aren’t enough
  9. @edeandrea #RedHat #RivieraDev2023 “Will someone get this big walking carpet

    out of my way?” – Princess Leia Demo The limitations of unit tests https://github.com/edeandrea/pact-quarkus-wookie-carpet-demo
  10. @edeandrea #RedHat #RivieraDev2023 “Will someone get this big walking carpet

    out of my way?” – Princess Leia Demo The limitations of unit tests https://github.com/edeandrea/pact-quarkus-wookie-carpet-demo
  11. @edeandrea #RedHat #RivieraDev2023 ✔ our tests ✔ their tests ✔

    reality our code their code contract test mock functional test A better mock
  12. @edeandrea #RedHat #RivieraDev2023 ✔ our tests ✘ their tests ✘

    reality our code their code contract test mock functional test A better mock
  13. @edeandrea #RedHat #RivieraDev2023 ✘ our tests ✔ their tests ✘

    reality A better mock our code their code contract test mock functional test
  14. @edeandrea #RedHat #RivieraDev2023 contract consumer tests mock declare (Pact) Pact

    file Consumer-driven contract testing Spring Cloud Contract Pact
  15. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock declare (Pact)

    contract tests verify Pact file Consumer-driven contract testing Spring Cloud Contract Pact Pact
  16. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock declare (Pact)

    contract tests verify Pact file Consumer-driven contract testing ☑ rich semantic testing Spring Cloud Contract Pact Pact
  17. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock declare (Pact)

    contract tests verify Pact file Consumer-driven contract testing ☑ rich semantic testing ☑ provider can ‘develop to the contract’ instead of developing speculatively (TDD) Spring Cloud Contract Pact Pact
  18. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock declare (Pact)

    contract tests verify Pact file Consumer-driven contract testing ☑ rich semantic testing ☑ provider can ‘develop to the contract’ instead of developing speculatively (TDD) ⛔ existing spec assets cannot be re-purposed Spring Cloud Contract Pact Pact
  19. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock declare (Pact)

    contract tests verify Pact file Consumer-driven contract testing ☑ rich semantic testing ☑ provider can ‘develop to the contract’ instead of developing speculatively (TDD) ⛔ existing spec assets cannot be re-purposed ⛔ provider needs to know who consumers are Spring Cloud Contract Pact Pact
  20. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock declare (Pact)

    contract tests verify Pact file Consumer-driven contract testing ☑ rich semantic testing ☑ provider can ‘develop to the contract’ instead of developing speculatively (TDD) ⛔ existing spec assets cannot be re-purposed ⛔ provider needs to know who consumers are ⛔ consumers can break provider CI Spring Cloud Contract Pact Pact
  21. @edeandrea #RedHat #RivieraDev2023 contract consumer provider OpenAPI Provider-driven contract testing

    generate (OpenAPI snapshot of current implementation) other protocol specs
  22. @edeandrea #RedHat #RivieraDev2023 contract consumer provider contract tests verify OpenAPI

    Provider-driven contract testing generate (OpenAPI snapshot of current implementation) other protocol specs Schemathesis Microcks
  23. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock contract tests

    verify OpenAPI Provider-driven contract testing generate (OpenAPI snapshot of current implementation) other protocol specs Prism Microcks Schemathesis Microcks
  24. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock contract tests

    verify OpenAPI Provider-driven contract testing generate (OpenAPI snapshot of current implementation) other protocol specs ☑ familiar contract format Prism Microcks Schemathesis Microcks
  25. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock contract tests

    verify OpenAPI Provider-driven contract testing generate (OpenAPI snapshot of current implementation) other protocol specs ☑ familiar contract format ☑ provider does not need comms with consumers Prism Microcks Schemathesis Microcks
  26. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock contract tests

    verify OpenAPI Provider-driven contract testing generate (OpenAPI snapshot of current implementation) other protocol specs ☑ familiar contract format ☑ provider does not need comms with consumers ⛔ provider does not get insight into how API is being used (deprecation is harder) Prism Microcks Schemathesis Microcks
  27. @edeandrea #RedHat #RivieraDev2023 contract consumer tests provider mock contract tests

    verify OpenAPI Provider-driven contract testing generate (OpenAPI snapshot of current implementation) other protocol specs ☑ familiar contract format ☑ provider does not need comms with consumers ⛔ provider does not get insight into how API is being used (deprecation is harder) ⛔ spec-based tests lack functional depth Prism Microcks Schemathesis Microcks
  28. @edeandrea #RedHat #RivieraDev2023 Is OpenAPI enough? It has the same

    syntax, but the semantics are different. It looks the same, but the behaviour is different.
  29. @edeandrea #RedHat #RivieraDev2023 Is OpenAPI enough? It has the same

    syntax, but the semantics are different. It looks the same, but the behaviour is different. Looks like a storm trooper. Behaves like Luke. (because it it is Luke)
  30. @edeandrea #RedHat #RivieraDev2023 how annoying, the provider is returning 204.

    the contract expects 404, so my test is broken. quarkus will return 204 by default. 204 vs 404 - it’s more about the theory behind REST...if a caller asks for a resource the server doesn't have, it should be a 404 - same way if a user types in an invalid URL into the browser ugh, it’s too late at night to care about REST theory. I’m just going to update the expectations in the test to match reality. what?! why is my other contract test broken now? 
 oh … because what I’m changing is a mock…. Based on a true story….
  31. @edeandrea #RedHat #RivieraDev2023 soo … microservices testing is hard limit

    end-to-end testing mocks will not be enough contract testing can rescue you
  32. @edeandrea #RedHat #RivieraDev2023 Kubernetes Native Java with Quarkus Deployment Developer

    Joy • Quickly & easily build Kubernetes-Native Java applications • Industry leader in startup time and memory utilization for native and JVM applications • One step native executable generation • Leverage existing Java, Jakarta, MicroProfile, & Spring expertise • Imperative & reactive APIs side-by-side • Live coding with zero config https://www.infoq.com/articles/native-java-quarkus