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

Fake it until you make it. ITs with WireMock, T...

Avatar for Oleg Nenashev Oleg Nenashev PRO
January 27, 2025
55

Fake it until you make it. ITs with WireMock, Testcontainers and Quarkus

Testcontainers has become one of the most popular tools for software integration testing. If you can put your system-under-test into a container, Docker compose cluster or a pod, this is what you're likely to use. If your target isn't ready, not containerizable or just too heavy for testing as is, you can always use mock testing frameworks, e.g. WireMock or MockServer in the JVM ecosystem. Can you combine both approaches? Sure!

In this talk, we will classify integration testing and discuss application areas for WireMock and Testcontainers, and discuss which tool to choose for each use-case. And why not both? We will discuss putting WireMock into Testcontainers, and getting the best from their features thanks to the new WireMock modules for Testcontainers. Last but not least, we will see how to put WireMock in front of the Testcontainers or your real system to do deeper tests or even chaos engineering.

P.S: We will focus on the Java, Golang or Rust examples, but the same approaches can be used everywhere

Copyright Notice: Gradle, Inc. Gradle®, Develocity®, Build Scan®, and the Gradlephant logo are registered trademarks of Gradle, Inc. "Gradle" means "Gradle Build Tool" and does not reference Gradle, Inc. and/or its subsidiaries

Avatar for Oleg Nenashev

Oleg Nenashev PRO

January 27, 2025
Tweet

More Decks by Oleg Nenashev

Transcript

  1. Oleg Nenashev @oleg_nenashev Fake it until you `make it` API

    Integration testing with Testcontainers, WireMock and Quarkus IET Summit, 27 January 2025
  2. > whoami @oleg_nenashev oleg-nenashev Dr. Nenashev / Mr. Jenkins Community

    Builder Developer Tools Hacker Independent Consultant #RussiansAgainstPutin #StandWithUkraine
  3. Integration Testing 12 • Multiple technology stacks and toolchains •

    Many teams involved • Sacred knowledge • [Almost] always too late
  4. APIs are the Key for Developer Productivity response request Client

    App Server HTTP/2 Storage response request API API
  5. 18 Staging & QA Tests Build Integration tests Build Tests

    Gaining confidence in you software “Shift Left” with modern tools
  6. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock) 4. Mocking at the code level Slow Fast Nope Accu- rate * For Testcontainers, see the slides
  7. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock or Microcks) 4. Mocking at the code level Slow Fast Nope Accu- rate * For Testcontainers, see the slides
  8. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Modeling (aka Mocking) at the API provider level (e.g. WireMock or Microcks) 4. Mocking at the code level Slow Fast Nope Accu- rate * For Testcontainers, see the slides
  9. API Mocking Tools Main implementation in Java Native lib, Docker

    images and Testcontainers modules Support for GraalVM Rich Ecosystem Sandbox CNCF Project Golang / Microservice arch Docker image, Testcontainers module, All-in K8s Charts Less Rich Ecosystem
  10. wiremock.org/docs/stubbing IF (request_url) THEN (response) * * it gets MUCH

    more complex WireMock Config JSON: Client library response request Client App Mock API Server HTTP/2 API Mocking 101
  11. WireMock Ecosystem / Java • Java • Kotlin • Scala

    • Groovy • Clojure • (?)Android 38 • JUnit 4/5 • Testcontainers • Sprint Boot • Spring Cloud Contract • Quarkus • Maven / Gradle Build Tool • Spock • Pact * Gradle® and the Gradlephant logo are registered trademarks of Gradle, Inc. "Gradle" means "Gradle Build Tool" and does not reference Gradle, Inc. and/or its subsidiaries
  12. WireMock as a Proxy Tests API Provider • Fault injection

    • Recording • Protocol Verification
  13. Choosing a right tool * • Need database or complex

    dynamic environment? ◦ YES => Testcontainers • Do you have a ready implementation? ◦ NO => WireMock/Microcks • Is it containerized and lightweight? ◦ NO => WireMock/Microcks • Can you easily trigger the desired scenarios? ◦ NO => WireMock/Microcks • Else: => Testcontainers 44 * Your mileage may vary ** More later *** I just like footnotes * Likely, you want to use both
  14. 45

  15. WireMock Proxy? Why? • Record & Playback for Request sequences

    • Reverse engineering of legacy undocumented APIs • NEW: OpenAPI Standard Compliance Verification (in 3.0 Beta) • Emulating complex cases ◦ Overriding particular responses ◦ Emulating response sequences / Stateful behavior ◦ Failure Injection 48
  16. If you like / use You can do [almost] the

    same as below Devoxx BE Video with Oleg Shelajev: youtube.com/watch?v=eFILbyaMI2A Our demo: github.com/testcontainers-community/ testcontainers-wiremock-demo 50 TL;DR: Two Olegs
  17. Quarkus Dev Services • Automatic provisioning of unconfigured services in

    development and test mode • Transparent to your application • Mostly containerized, with Testcontainers 52 https://quarkus.io/guides/dev-services
  18. Dev Services • Mostly containerized, with Testcontainers 53 Presentation by

    Daniel Oh: https://www.youtube.com/watch?v=moIFTj9KW1c
  19. More Demos • Simple WireMock and Testcontainers demo: github.com/testcontainers-community/testcontainers-wiremock-demo •

    WireMock and Docker integration tests: https://github.com/wiremock/wiremock-docker • Quarkus Dev Service for WireMock and Testcontainers: https://github.com/oleg-nenashev/gradle-quarkus-plugin-demo • Spring Boot + Testcontainers and WireMock + LocalStack: https://github.com/oleg-nenashev/mocks-as-code-demo
  20. Takeaways 63 • Shift left the integration testing • API

    Mocking / abstraction are great… when used right • There is no silver bullet • WireMock and Testcontainers address their own use-cases • They work well together!
  21. Choosing a right tool * • Need database or complex

    dynamic environment? ◦ YES => Testcontainers • Do you have a ready implementation? ◦ NO => WireMock/Microcks • Is it containerized and lightweight? ◦ NO => WireMock/Microcks • Can you easily trigger the desired scenarios? ◦ NO => WireMock/Microcks • Else: => Testcontainers 64 * Your mileage may vary ** More later *** I just like footnotes * Likely, you want to use both
  22. Credits 69 • All WireMock, Testcontainers and Quarkus contributors •

    Siva Prasad Reddy, JetBrains and Oleg Shelajev, Docker • All FOSS folks