Slide 1

Slide 1 text

Fake it until you make it API Integration testing with Testcontainers and WireMock Oleg Nenashev, WireMock Oleg Šelajev, AtomicJar

Slide 2

Slide 2 text

2

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

4

Slide 5

Slide 5 text

5

Slide 6

Slide 6 text

6

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

> whoami @oleg_nenashev oleg-nenashev Dr. Nenashev / Mr. Jenkins Developer tools hacker Community builder & DevRel consultant #RussiansAgainstPutin #StandWithUkraine

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

10

Slide 11

Slide 11 text

11 Staging & QA Tests Build Integration tests Gaining confidence in you software

Slide 12

Slide 12 text

12 Staging & QA Tests Build Integration tests Build Tests Gaining confidence in you software

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

14

Slide 15

Slide 15 text

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.

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

18 Source: https://medium.com/10-minutes-qa-story/api-testing-from-scratch-api-anatomy-f220856ce9b3

Slide 19

Slide 19 text

APIs

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

21

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

WireMock Ecosystem & Features 24 wiremock.org/docs

Slide 25

Slide 25 text

WireMock Ecosystem & Features 25 wiremock.org/docs

Slide 26

Slide 26 text

WireMock in Java 26 wiremock.org/docs/stubbing

Slide 27

Slide 27 text

WireMock Ecosystem & Features 27 wiremock.org/docs

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Example - WireMock for Rust 29 docs.rs/wiremock/latest/wiremock LukeMathWalker/wiremock-rs Note: WireMock for Rust is maintained outside the WireMock GitHub organization

Slide 30

Slide 30 text

30 2500+ Mock API Templates for common services library.wiremock.org

Slide 31

Slide 31 text

WireMock Distributions 31

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

33 Better Together!

Slide 34

Slide 34 text

34

Slide 35

Slide 35 text

35 WireMock offers an official Testcontainers module! testcontainers.com/modules/wiremock

Slide 36

Slide 36 text

Example - JUnit 5 36

Slide 37

Slide 37 text

37

Slide 38

Slide 38 text

Example 1 - Testing of WireMock Docker images 38 ● Java, Testcontainers, JUnit5 ● Sources location: github.com/wiremock/wiremock-docker /tree/main/test/integration-tests

Slide 39

Slide 39 text

Example 2 - Golang 39 ● Golang, Testcontainers, WireMock Module ● Sources location: github.com/wiremock/wiremock-testcontain ers-go/tree/main/examples/quickstart

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

41

Slide 42

Slide 42 text

WireMock as a Proxy 42 Tests API Provider ● Fault injection ● Recording ● Protocol Verification

Slide 43

Slide 43 text

43

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

45 Let’s talk at Booth #20

Slide 46

Slide 46 text

It’s [always] a great time to contribute! wiremock.org/participate testcontainers.org/contributing 46

Slide 47

Slide 47 text

THANK YOU 47 wiremock.org/testcontainers slack.wiremock.org slack.testcontainers.com github.com/shelajev/testcontainers-wiremock-demo wiremock.org testcontainers.com 🏢

Slide 48

Slide 48 text

Credits to ● All WireMock contributors ● WireMock Inc. Team ● All Testcontainers contributors and AtomicJar folks ● All FOSS contributors 48