Slide 1

Slide 1 text

contract testing with pact and quarkus Holly Cummins Red Hat @[email protected]

Slide 2

Slide 2 text

@holly_cummins the big microservices question

Slide 3

Slide 3 text

@holly_cummins “how do I know the whole system works? the big microservices question

Slide 4

Slide 4 text

@holly_cummins “how do I know the whole system works? … without losing the goodness of microservices?” the big microservices question

Slide 5

Slide 5 text

can you deploy independently? v5.1.4 v5.1.4 v5.1.4 v5.1.4

Slide 6

Slide 6 text

can you deploy independently? v6.2.8 v65.7 v5.1.4 v1.0.5

Slide 7

Slide 7 text

do you have confidence in how individual services are tested? v6.2.8 v65.7 v5.1.4 v1.0.5

Slide 8

Slide 8 text

@holly_cummins #RedHat “we made our pipeline enforce releasing all our microservices at the same time.” true story

Slide 9

Slide 9 text

@holly_cummins #RedHat “we made our pipeline enforce releasing all our microservices at the same time.” true story are you dependent on end-to-end testing?

Slide 10

Slide 10 text

@holly_cummins testing in isolation is not enough

Slide 11

Slide 11 text

@holly_cummins distributed != decoupled

Slide 12

Slide 12 text

@holly_cummins “every time we touch one microservice, all the others break.”

Slide 13

Slide 13 text

@holly_cummins “ohhhh, we weren’t expecting your service to do that … “

Slide 14

Slide 14 text

@holly_cummins “uh, what do you mean you corrected the typo in your json?”

Slide 15

Slide 15 text

@holly_cummins “surely the right way to handle missing data is a 204?”

Slide 16

Slide 16 text

@holly_cummins #RedHat their code our code why mocks aren’t enough

Slide 17

Slide 17 text

@holly_cummins #RedHat our code our mock why mocks aren’t enough

Slide 18

Slide 18 text

@holly_cummins #RedHat our code our mock tests ✔ why mocks aren’t enough

Slide 19

Slide 19 text

@holly_cummins #RedHat our code our mock our code their actual code tests ✔ why mocks aren’t enough

Slide 20

Slide 20 text

@holly_cummins #RedHat our code our mock our code their actual code tests ✔ reality ✘ why mocks aren’t enough

Slide 21

Slide 21 text

@holly_cummins demo: the limitations of unit tests

Slide 22

Slide 22 text

@holly_cummins #RedHat our code their code why mocks aren’t enough

Slide 23

Slide 23 text

@holly_cummins #RedHat our code their code contract test why mocks aren’t enough

Slide 24

Slide 24 text

@holly_cummins #RedHat our code their code contract test mock why mocks aren’t enough

Slide 25

Slide 25 text

@holly_cummins #RedHat our code their code contract test mock functional test why mocks aren’t enough

Slide 26

Slide 26 text

@holly_cummins #RedHat our code their code contract test mock functional test our tests ✔ their tests ✔ reality ✔ why mocks aren’t enough

Slide 27

Slide 27 text

@holly_cummins #RedHat our code their code contract test mock functional test why mocks aren’t enough

Slide 28

Slide 28 text

@holly_cummins #RedHat our code their code contract test mock functional test our tests ✔ their tests ✘ reality ✘ why mocks aren’t enough

Slide 29

Slide 29 text

@holly_cummins #RedHat our code their code contract test mock functional test why mocks aren’t enough

Slide 30

Slide 30 text

@holly_cummins #RedHat our code their code contract test mock functional test our tests ✘ their tests ✔ reality ✘ why mocks aren’t enough

Slide 31

Slide 31 text

IBM Cloud © 2020 IBM Corporation

Slide 32

Slide 32 text

IBM Cloud © 2020 IBM Corporation the test pyramid

Slide 33

Slide 33 text

IBM Cloud © 2020 IBM Corporation the test pyramid end-to-end tests

Slide 34

Slide 34 text

IBM Cloud © 2020 IBM Corporation the test pyramid end-to-end tests unit tests

Slide 35

Slide 35 text

IBM Cloud © 2020 IBM Corporation the test pyramid end-to-end tests unit tests contract tests

Slide 36

Slide 36 text

#RedHat @holly_cummins How to test a fire alarm?

Slide 37

Slide 37 text

IBM Cloud © 2020 IBM Corporation how not to test a fire alarm

Slide 38

Slide 38 text

IBM Cloud © 2020 IBM Corporation how not to test a fire alarm

Slide 39

Slide 39 text

#RedHat @holly_cummins

Slide 40

Slide 40 text

#RedHat @holly_cummins unit testing a fire alarm

Slide 41

Slide 41 text

#RedHat @holly_cummins uh … is that enough?

Slide 42

Slide 42 text

#RedHat @holly_cummins contract testing a fire alarm

Slide 43

Slide 43 text

#RedHat @holly_cummins contract testing a fire alarm

Slide 44

Slide 44 text

@holly_cummins demo: how pact helps

Slide 45

Slide 45 text

@holly_cummins #RedHat if you remember one thing …

Slide 46

Slide 46 text

@holly_cummins #RedHat if you remember one thing … • don’t test the mock! • your consumer test should be testing your code, not what’s coming back from the other side • lots of examples get this wrong :(

Slide 47

Slide 47 text

@holly_cummins #RedHat don’t test the mock.

Slide 48

Slide 48 text

@holly_cummins #RedHat but we use openapi?

Slide 49

Slide 49 text

@holly_cummins demo: semantic testing with pact

Slide 50

Slide 50 text

@holly_cummins #RedHat cold person knitter sheep farmer semantics vs syntax (why sharing expectations about behaviour is important)

Slide 51

Slide 51 text

@holly_cummins #RedHat cold person knitter sheep farmer “white sweater, please” semantics vs syntax (why sharing expectations about behaviour is important)

Slide 52

Slide 52 text

@holly_cummins #RedHat cold person knitter sheep farmer “white sweater, please” semantics vs syntax (why sharing expectations about behaviour is important)

Slide 53

Slide 53 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” semantics vs syntax (why sharing expectations about behaviour is important)

Slide 54

Slide 54 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” white wool semantics vs syntax (why sharing expectations about behaviour is important)

Slide 55

Slide 55 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” white wool semantics vs syntax (why sharing expectations about behaviour is important)

Slide 56

Slide 56 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” white wool semantics vs syntax (why sharing expectations about behaviour is important)

Slide 57

Slide 57 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” white wool black sweater semantics vs syntax (why sharing expectations about behaviour is important)

Slide 58

Slide 58 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” white wool black sweater black wool semantics vs syntax (why sharing expectations about behaviour is important)

Slide 59

Slide 59 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” “pink sweater, please” white wool black sweater black wool semantics vs syntax (why sharing expectations about behaviour is important)

Slide 60

Slide 60 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” “pink sweater, please” white wool black sweater black wool semantics vs syntax (why sharing expectations about behaviour is important)

Slide 61

Slide 61 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” “pink sweater, please” white wool black sweater black wool pink sweater semantics vs syntax (why sharing expectations about behaviour is important)

Slide 62

Slide 62 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” “pink sweater, please” white wool black sweater black wool pink sweater pink wool semantics vs syntax (why sharing expectations about behaviour is important)

Slide 63

Slide 63 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” “pink sweater, please” white wool black sweater black wool pink sweater pink wool semantics vs syntax (why sharing expectations about behaviour is important) what?! pink sheep don’t exist

Slide 64

Slide 64 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” “pink sweater, please” white wool black sweater black wool pink sweater pink wool semantics vs syntax (why sharing expectations about behaviour is important) should the knitter ask for white wool and bring in a dyeing service? what?! pink sheep don’t exist

Slide 65

Slide 65 text

@holly_cummins #RedHat cold person white sweater knitter sheep farmer “white sweater, please” “black sweater, please” “pink sweater, please” white wool black sweater black wool pink sweater pink wool semantics vs syntax (why sharing expectations about behaviour is important) should the knitter ask for white wool and bring in a dyeing service? should the farmer dye the wool? what?! pink sheep don’t exist

Slide 66

Slide 66 text

@holly_cummins #RedHat was this a realistic demo?

Slide 67

Slide 67 text

@holly_cummins #RedHat Photo of sheep at the Latitude Festival by Tim Parkinson, https://www.flickr.com/photos/timparkinson

Slide 68

Slide 68 text

@holly_cummins #RedHat Photo of sheep at the Latitude Festival by Tim Parkinson, https://www.flickr.com/photos/timparkinson “pink sheep don’t exist”

Slide 69

Slide 69 text

@holly_cummins #RedHat 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 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….

Slide 70

Slide 70 text

@holly_cummins #RedHat contract testing landscape

Slide 71

Slide 71 text

@holly_cummins #RedHat provider contract testing landscape

Slide 72

Slide 72 text

@holly_cummins #RedHat consumer provider contract testing landscape

Slide 73

Slide 73 text

@holly_cummins #RedHat contract consumer provider contract testing landscape

Slide 74

Slide 74 text

@holly_cummins #RedHat contract consumer provider contract tests verify Pact (functional tests) contract testing landscape

Slide 75

Slide 75 text

@holly_cummins #RedHat contract consumer tests provider mock Pact contract tests verify Pact (functional tests) contract testing landscape

Slide 76

Slide 76 text

@holly_cummins #RedHat contract consumer tests provider mock Pact declare (Pact) contract tests verify Pact (functional tests) contract testing landscape Pact file

Slide 77

Slide 77 text

@holly_cummins #RedHat contract consumer tests provider mock Pact declare (Pact) contract tests verify Pact (functional tests) OpenAPI contract testing landscape Pact file

Slide 78

Slide 78 text

@holly_cummins #RedHat contract consumer tests provider mock Pact declare (Pact) contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file

Slide 79

Slide 79 text

@holly_cummins #RedHat contract consumer tests provider mock Pact declare (Pact) contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file Microcks

Slide 80

Slide 80 text

@holly_cummins #RedHat contract consumer tests provider mock Pact Prism (OpenAPI) declare (Pact) contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file Microcks

Slide 81

Slide 81 text

@holly_cummins #RedHat contract consumer tests provider mock Pact Prism (OpenAPI) Microcks (OpenAPI) declare (Pact) contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file Microcks

Slide 82

Slide 82 text

@holly_cummins #RedHat contract consumer tests provider mock Pact Prism (OpenAPI) Microcks (OpenAPI) declare (Pact) contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file mock server OpenAPI + Prism Microcks Microcks

Slide 83

Slide 83 text

@holly_cummins #RedHat contract consumer tests provider mock Pact Prism (OpenAPI) Microcks (OpenAPI) declare (Pact) contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file generate (OpenAPI snapshot of current implementation) mock server OpenAPI + Prism Microcks Microcks

Slide 84

Slide 84 text

@holly_cummins #RedHat contract consumer tests provider mock Pact Prism (OpenAPI) Microcks (OpenAPI) declare (Pact) generate skeleton from OpenAPI contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file generate (OpenAPI snapshot of current implementation) mock server OpenAPI + Prism Microcks Microcks

Slide 85

Slide 85 text

@holly_cummins #RedHat contract consumer tests provider mock Pact Prism (OpenAPI) Microcks (OpenAPI) declare (Pact) generate skeleton from OpenAPI contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file dashboard generate (OpenAPI snapshot of current implementation) mock server OpenAPI + Prism Microcks Microcks

Slide 86

Slide 86 text

@holly_cummins #RedHat contract consumer tests provider mock Pact Prism (OpenAPI) Microcks (OpenAPI) declare (Pact) generate skeleton from OpenAPI contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file dashboard Pact broker generate (OpenAPI snapshot of current implementation) mock server OpenAPI + Prism Microcks Microcks

Slide 87

Slide 87 text

@holly_cummins #RedHat contract consumer tests provider mock Pact Prism (OpenAPI) Microcks (OpenAPI) declare (Pact) generate skeleton from OpenAPI contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file dashboard Pact broker Microcks generate (OpenAPI snapshot of current implementation) mock server OpenAPI + Prism Microcks Microcks

Slide 88

Slide 88 text

@holly_cummins #RedHat contract consumer tests provider mock Pact Prism (OpenAPI) Microcks (OpenAPI) declare (Pact) generate skeleton from OpenAPI contract tests verify Pact (functional tests) OpenAPI OpenAPI + Schemathesis (syntax only, weaker connection to consumer expectations) contract testing landscape Pact file dashboard Pact broker Microcks generate (OpenAPI snapshot of current implementation) mock server OpenAPI + Prism Microcks Microcks other protocol specs

Slide 89

Slide 89 text

@holly_cummins #RedHat provider-driven contract testing

Slide 90

Slide 90 text

@holly_cummins #RedHat provider provider-driven contract testing

Slide 91

Slide 91 text

@holly_cummins #RedHat contract provider provider-driven contract testing generate (OpenAPI snapshot of current implementation)

Slide 92

Slide 92 text

@holly_cummins #RedHat contract provider contract tests verify provider-driven contract testing generate (OpenAPI snapshot of current implementation)

Slide 93

Slide 93 text

@holly_cummins #RedHat contract consumer provider contract tests verify provider-driven contract testing generate (OpenAPI snapshot of current implementation)

Slide 94

Slide 94 text

@holly_cummins #RedHat contract consumer tests provider mock contract tests verify provider-driven contract testing generate (OpenAPI snapshot of current implementation)

Slide 95

Slide 95 text

@holly_cummins #RedHat contract consumer tests provider mock contract tests verify OpenAPI provider-driven contract testing generate (OpenAPI snapshot of current implementation)

Slide 96

Slide 96 text

@holly_cummins #RedHat contract consumer tests provider mock contract tests verify OpenAPI provider-driven contract testing generate (OpenAPI snapshot of current implementation) other protocol specs

Slide 97

Slide 97 text

@holly_cummins #RedHat 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

Slide 98

Slide 98 text

@holly_cummins #RedHat 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

Slide 99

Slide 99 text

@holly_cummins #RedHat 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

Slide 100

Slide 100 text

@holly_cummins #RedHat 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 - spec-based tests lack depth

Slide 101

Slide 101 text

@holly_cummins #RedHat consumer-driven contract testing

Slide 102

Slide 102 text

@holly_cummins #RedHat consumer consumer-driven contract testing

Slide 103

Slide 103 text

@holly_cummins #RedHat contract consumer tests declare (Pact) Pact file consumer-driven contract testing

Slide 104

Slide 104 text

@holly_cummins #RedHat contract consumer tests mock declare (Pact) Pact file consumer-driven contract testing

Slide 105

Slide 105 text

@holly_cummins #RedHat contract consumer tests provider mock declare (Pact) Pact file consumer-driven contract testing

Slide 106

Slide 106 text

@holly_cummins #RedHat contract consumer tests provider mock declare (Pact) contract tests verify Pact file consumer-driven contract testing

Slide 107

Slide 107 text

@holly_cummins #RedHat contract consumer tests provider mock declare (Pact) contract tests verify OpenAPI Pact file consumer-driven contract testing

Slide 108

Slide 108 text

@holly_cummins #RedHat contract consumer tests provider mock declare (Pact) contract tests verify OpenAPI Pact file other protocol specs consumer-driven contract testing

Slide 109

Slide 109 text

@holly_cummins #RedHat contract consumer tests provider mock declare (Pact) contract tests verify OpenAPI Pact file other protocol specs consumer-driven contract testing + rich semantic testing

Slide 110

Slide 110 text

@holly_cummins #RedHat contract consumer tests provider mock declare (Pact) contract tests verify OpenAPI Pact file other protocol specs consumer-driven contract testing + rich semantic testing + provider can ‘develop to the test’ instead of developing speculatively

Slide 111

Slide 111 text

@holly_cummins #RedHat contract consumer tests provider mock declare (Pact) contract tests verify OpenAPI Pact file other protocol specs consumer-driven contract testing + rich semantic testing + provider can ‘develop to the test’ instead of developing speculatively - existing spec assets cannot be re-purposed

Slide 112

Slide 112 text

@holly_cummins #RedHat contract consumer tests provider mock declare (Pact) contract tests verify OpenAPI Pact file other protocol specs consumer-driven contract testing + rich semantic testing + provider can ‘develop to the test’ instead of developing speculatively - existing spec assets cannot be re-purposed - provider needs to identify consumers

Slide 113

Slide 113 text

@holly_cummins #RedHat contract consumer tests provider mock declare (Pact) contract tests verify OpenAPI Pact file other protocol specs consumer-driven contract testing + rich semantic testing + provider can ‘develop to the test’ instead of developing speculatively - existing spec assets cannot be re-purposed - provider needs to identify consumers - consumers can break provider CI

Slide 114

Slide 114 text

@holly_cummins #RedHat “contract-first”

Slide 115

Slide 115 text

@holly_cummins #RedHat

Slide 116

Slide 116 text

@holly_cummins #RedHat some contract testing options

Slide 117

Slide 117 text

@holly_cummins #RedHat some contract testing options • Pact

Slide 118

Slide 118 text

@holly_cummins #RedHat some contract testing options • Pact • Microcks

Slide 119

Slide 119 text

@holly_cummins #RedHat some contract testing options • Pact • Microcks • Spring Cloud Contract

Slide 120

Slide 120 text

@holly_cummins #RedHat some contract testing options • Pact • Microcks • Spring Cloud Contract • OpenAPI + schema validation + mock generation • Prism • Schemathesis

Slide 121

Slide 121 text

Want to know/learn/watch more about Quarkus? ● Battle of the frameworks : Quarkus vs SpringBoot (11:10-11:50, MC2) ● Stream processing app. with Kafka and Quarkus (12:20-13:00, MC2) ● Quarkus on AWS Lambda (14:10-14:25, MC3) ● Why and when to write a Quarkus extension (14:35-14:50, MC3) ● Quarkus Community BOF (15:05-16:05, MC3) ⇨ OpenId Connect and JWT Security in Quarkus (17:30-18:10, MC2)

Slide 122

Slide 122 text

@[email protected] http://hollycummins.com/contract-testing-devoxx-greece/ slides thank you!

Slide 123

Slide 123 text

@holly_cummins #RedHat maturity model for quarkus extensions

Slide 124

Slide 124 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works

Slide 125

Slide 125 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works (a) works in JVM mode

Slide 126

Slide 126 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works (a) works in JVM mode (b)works in dev mode

Slide 127

Slide 127 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works (a) works in JVM mode (b)works in dev mode (c) works in native

Slide 128

Slide 128 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works (a) works in JVM mode (b)works in dev mode (c) works in native 2. developer joy

Slide 129

Slide 129 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works (a) works in JVM mode (b)works in dev mode (c) works in native 2. developer joy (a) use build-time application knowledge to remove boilerplate

Slide 130

Slide 130 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works (a) works in JVM mode (b)works in dev mode (c) works in native 2. developer joy (a) use build-time application knowledge to remove boilerplate 3. developer service (if there is an external service dependency)

Slide 131

Slide 131 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works (a) works in JVM mode (b)works in dev mode (c) works in native 2. developer joy (a) use build-time application knowledge to remove boilerplate 3. developer service (if there is an external service dependency) 4. dev UI

Slide 132

Slide 132 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works (a) works in JVM mode (b)works in dev mode (c) works in native 2. developer joy (a) use build-time application knowledge to remove boilerplate 3. developer service (if there is an external service dependency) 4. dev UI 5. quickstart code template

Slide 133

Slide 133 text

@holly_cummins #RedHat maturity model for quarkus extensions 1. actually works (a) works in JVM mode (b)works in dev mode (c) works in native 2. developer joy (a) use build-time application knowledge to remove boilerplate 3. developer service (if there is an external service dependency) 4. dev UI 5. quickstart code template quarkus-pact