Slide 1

Slide 1 text

Developing subatomic apps With Quarkus and WireMock Oleg Nenashev, WireMock Inc

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

3 rts.ch/info/regions/neuchatel/12836885-la-population-neuchateloise-en-hausse-malgre-un-recul-dans-les-montagnes.html

Slide 4

Slide 4 text

WireMock Cloud by WireMock Inc. 4 ● 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 5

Slide 5 text

Outline ● Intro to API integration testing and WireMock ● Using WireMock and Quarkus ● And examples! 5

Slide 6

Slide 6 text

> whoami --quarkus ● Jenkins on Quarkus experiments ● Jenkinsfile Runner native exec with Quarkus ● FaaScinator pet project (Stale) ● Wishlist: WireMock + Quarkus image 6

Slide 7

Slide 7 text

Docker image for OpenFaaS openfaas/of-watchdog AdoptOpenJDK JDK/JRE Service Wrapper GET / run function GET /help GET /usage GET /schema Config and schema (env vars, sys prop) User CLI app Quarkus github.com/oleg-nenashev/faascinator ¡Stale project!

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

APIs are essential for Integration Testing 9 GROWTH IN WEB APIS SINCE 2005 Over 90% of developers use APIs. Skyrocket growth of APIs JANUARY 2006 JANUARY 2008 JANUARY 2010 JANUARY 2012 JANUARY 2014 JANUARY 2016 JANUARY 2018 MONTH The growth over time of the Programmable Web API API directory to more than 22,000 entries 22000 20000 18000 16000 14000 12000 10000 8000 6000 4000 2000 0 TOTAL API COUNT Programmable Web * Gartner Hype Cycle for APIs, 2022

Slide 10

Slide 10 text

APIs

Slide 11

Slide 11 text

Quarkus is great for building REST APIs 11 ● Built-in support ● Many extensions ● Developer experience https://code.quarkus.io/

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

xkcd.com/303 www.jenkins.io/artwork

Slide 15

Slide 15 text

15

Slide 16

Slide 16 text

16

Slide 17

Slide 17 text

xkcd.com/303 www.jenkins.io/artwork

Slide 18

Slide 18 text

Source: https://en.wikipedia.org/wiki/Groundhog_Day_(film)

Slide 19

Slide 19 text

19

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

23 Build Unit tests Publish Reports Integration tests Publish Reports WAS

Slide 24

Slide 24 text

Integration testing? 24 ● Multiple technology stacks and toolchains ● Many teams involved ● Sacred knowledge ● [Almost] always too late

Slide 25

Slide 25 text

25 Build Unit tests Publish Reports Integration tests Publish Reports NOW “Shift Left” Fast integrations tests are critical

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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 27 Slow Fast Nope Accu- rate

Slide 28

Slide 28 text

28 Staging & QA Tests Build Integration tests Build Tests Gaining confidence in you software “Shift Left”

Slide 29

Slide 29 text

29

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

31 WireMock 101 WireMock is a tool for building mock APIs Created in 2011 as a Java test library and CLI Available beyond Java/JVM, inc Python or Golang You can can: ● Create stable development environments ● Isolate yourself from flakey 3rd parties ● Simulate APIs that don't exist yet wiremock.org

Slide 32

Slide 32 text

32 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 33

Slide 33 text

UI - WireMock Cloud Using WireMock Cloud app.wiremock.cloud 33

Slide 34

Slide 34 text

WireMock in Java 34 wiremock.org/docs/stubbing

Slide 35

Slide 35 text

WireMock Ecosystem & Features 35 wiremock.org/docs

Slide 36

Slide 36 text

WireMock Ecosystem & Features 36 wiremock.org/docs

Slide 37

Slide 37 text

WireMock & JVM Ecosystem - projects for… ● Java ● Kotlin ● Scala ● Groovy ● Clojure ● Android (in 2.x) 37 ● JUnit 4/5 ● Testcontainers ● Sprint Boot ● Spring Cloud Contract ● Quarkus ● (*)Micronaut ● Maven/Gradle ● Spock ● Pact

Slide 38

Slide 38 text

38 WireMock has an official Testcontainers module! testcontainers.com/modules/wiremock

Slide 39

Slide 39 text

Example - JUnit 5 39

Slide 40

Slide 40 text

40 wiremock.org/docs/solutions/quarkus

Slide 41

Slide 41 text

41 docs.quarkiverse.io/quarkus-wiremock/dev/index.html

Slide 42

Slide 42 text

@QuarkusTest or @QuarkusIntegrationTest 42

Slide 43

Slide 43 text

And a Quarkus Dev Service! ● https://quarkus.io/guides/dev-services 43

Slide 44

Slide 44 text

44 https://docs.quarkiverse.io/quarkus-wiremock/dev/index.html# extension-configuration-reference

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

github.com/wiremock/wiremock-quarkus-devservice-demo * for Spring Boot github.com/shelajev/testcontainers-wiremock-demo

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

WireMock Public Roadmap 48 github.com/orgs/wiremock/projects/4

Slide 49

Slide 49 text

WireMock and Quarkus wishlist ● WireMock official images on Quarkus ● WireMock native packaging with Quarkus ● Ext: Full configuration-as-code in WireMock, build-time configuration in Quarkus ● Ext: Support for WireMock in the proxy mode ● Ext: Testcontainers-based Dev Service: extensions and portability 49

Slide 50

Slide 50 text

Wishlist - WireMock as a Proxy in Quarkus 50 Tests / Dev Real API Provider OR ● Fault injection ● Recording ● Protocol Verification

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Takeaways 52 ● Shift left your integration testing… as far as unit tests and developer environments ● Reduce external dependencies, mock APIs ● There are tools for that, including WireMock ● WireMock and Quarkus co-exist well

Slide 53

Slide 53 text

Get Started wiremock.org/docs wiremock.org/docs/solutions/quarkus 53

Slide 54

Slide 54 text

References My demo: TODO ● Similar one in Spring Boot: https://github.com/shelajev/testcontainers-wiremock-demo WireMock extension for Quarkus: ● https://docs.quarkiverse.io/quarkus-wiremock ● https://github.com/gscaramuzzino/quarkus-wiremock-testing ● https://quarkus.io/guides/getting-started-testing#quarkus-test-resource 54

Slide 55

Slide 55 text

THANK YOU Contacts: E-mail: [email protected] GitHub: oleg-nenashev Twitter: @oleg_nenashev QUESTIONS? 55