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

Fake it until you make it. Integration Testing ...

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Oleg Nenashev Oleg Nenashev PRO
October 10, 2023

Fake it until you make it. Integration Testing with Testcontainers and WireMock - Spring Boot Edition

Pair presentation together with Oleg Šelajev at Devoxx Belgium 2023

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 API testing frameworks like WireMock. 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 modules and integrations. 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 and maybe Golang examples, but the same approaches can be used in any technology stack for which the Testcontainers SDK is available.

OLEG NENASHEV
Oleg is a developer tools hacker, community builder and consultant currently working on WireMock and WireMock Cloud ecosystems. He's passionate open source software and open hardware advocate. Oleg is a core maintainer and board member in the Jenkins project where he writes code, mentors contributors and organizes community events. He is a TOC member in the Continuous Delivery Foundation, and also a CDF and CNCF ambassador. Oleg has a PhD degree in electronics design and volunteers in the Free and Open Source Silicon Foundation.

OLEG ŠELAJEV
Oleg Šelajev is a developer advocate at AtomicJar working on making integration tests with Testcontainers better for everyone in the community. VirtualJUG leader. Java Champion.

Avatar for Oleg Nenashev

Oleg Nenashev PRO

October 10, 2023
Tweet

Video

More Decks by Oleg Nenashev

Transcript

  1. Fake it until you make it API Integration testing with

    Testcontainers and WireMock Oleg Nenashev, WireMock Oleg Šelajev, AtomicJar
  2. 2

  3. 4

  4. 5

  5. 6

  6. Why are we here? 7 • Shift left your integration

    testing • Mocking APIs and services, reducing external dependencies, containers • There are tools for that, including WireMock and Testcontainers • They work well together! These slides
  7. > whoami @oleg_nenashev oleg-nenashev Dr. Nenashev / Mr. Jenkins Developer

    tools hacker Community builder & DevRel consultant #RussiansAgainstPutin #StandWithUkraine
  8. 10

  9. 13

  10. 14

  11. Debug your Testcontainers- powered dependencies The app lets you proxy

    any service to a fixed port to easily inspect it with your favorite debugging tools. Track and analyze your test sessions Dashboards that provide you and your team with insights into your development and testing patterns. Switch container runtimes and burst to the cloud With Testcontainers Cloud, you can even run them in the cloud on demand, while saving your local resources. Testcontainers Desktop The free companion app.
  12. 17

  13. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (with Testcontainers) 3. Mocking at the API provider level 4. Mocking at the code level 20 Slow Fast Accu- rate Nope
  14. 21

  15. 22 WireMock 101 WireMock is a tool for building mock

    APIs Created in 2011 as a Java test library and CLI You can can: • Create stable development environments • Isolate yourself from flakey 3rd parties • Simulate APIs that don't exist yet • Extend everything wiremock.org
  16. 23 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
  17. WireMock & JVM Ecosystem - projects for… • Java •

    Kotlin • Scala • Groovy • Clojure • (?)Android 28 • JUnit 4/5 • Testcontainers • Sprint Boot • Spring Cloud Contract • Quarkus • Maven/Gradle • Spock • Pact
  18. WireMock Cloud by WireMock Inc. 32 • Early stage startup

    • WireMock creator is a co-founder of the Inc. • WireMock Cloud - SaaS for end-to-end API mocking • Private beta: K8s Edition for managed / on-premises wiremock.io
  19. 34

  20. 37

  21. Example 1 - Testing of WireMock Docker images 38 •

    Java, Testcontainers, JUnit5 • Sources location: github.com/wiremock/wiremock-docker /tree/main/test/integration-tests
  22. Example 2 - Golang 39 • Golang, Testcontainers, WireMock Module

    • Sources location: github.com/wiremock/wiremock-testcontain ers-go/tree/main/examples/quickstart
  23. 41

  24. WireMock as a Proxy 42 Tests API Provider • Fault

    injection • Recording • Protocol Verification
  25. 43

  26. Mega Demo - Spring Boot App development … with a

    database and a Mock API server for Hacker News API See github.com/shelajev/testcontainers-wiremock-demo 44
  27. Credits to • All WireMock contributors • WireMock Inc. Team

    • All Testcontainers contributors and AtomicJar folks • All FOSS contributors 48