“Is It a Bird? Is It a Plane?” — The Weird Shapes We Use To Talk About Testing

A presentation at DDD Melbourne 2024 in March 2024 in Melbourne VIC, Australia by Julian Burr

Slide 1

Slide 1

MELBOURNE2024 “IS IT A BIRD? IS IT A PLANE?” THE WEIRD SHAPES WE USE TO TALK ABOUT TESTING

Slide 2

Slide 2

Proudly sponsored by MELBOURNE2024 Diamond Sponsors Platinum Sponsors Gold Sponsors Childcare by: Wi-Fi by: Coffee Cart by: Silver Sponsors

Slide 3

Slide 3

Play sponsor bingo and you can win MELBOURNE2024

Slide 4

Slide 4

MELBOURNE2024 “IS IT A BIRD? IS IT A PLANE?” THE WEIRD SHAPES WE USE TO TALK ABOUT TESTING

Slide 5

Slide 5

PART I: Common testing methodologies

Slide 6

Slide 6

THE DIFFERENT TYPES OF TESTS

Slide 7

Slide 7

THE DIFFERENT TYPES OF TESTS

  1. Unit tests your smallest units of code

Slide 8

Slide 8

THE DIFFERENT TYPES OF TESTS com bin un ati its o big t ger hat n of ser buil vic d es

  1. Unit tests 2. Integration tests s e c a f r e t n i e h t d n a s t i n u e h t between

Slide 9

Slide 9

https://www.reddit.com/r/ProgrammerHumor/comments/isidkn/unit_testing_vs_integration_testing/

Slide 10

Slide 10

THE DIFFERENT TYPES OF TESTS

  1. Unit tests 2. Integration tests 3. End-to-end tests the end-to-end behaviours of the system

Slide 11

Slide 11

THE DIFFERENT TYPES OF TESTS

  1. Static tests 2. Unit tests 3. Integration tests 4. End-to-end tests

Slide 12

Slide 12

THE DIFFERENT TYPES OF TESTS

  1. Static tests 2. Unit tests 3. Integration tests 4. End-to-end tests 5. Manual tests

Slide 13

Slide 13

“THE SHAPES”

Slide 14

Slide 14

“THE SHAPES” — THE PYRAMID e2e integration unit https://web.dev/articles/ta-strategies

Slide 15

Slide 15

“THE SHAPES” — THE PYRAMID more integrated e2e integration more isolated unit https://web.dev/articles/ta-strategies

Slide 16

Slide 16

“THE SHAPES” — THE PYRAMID slower & more expensive e2e integration faster & cheaper unit https://web.dev/articles/ta-strategies

Slide 17

Slide 17

“THE SHAPES” — THE ICE CONE e2e integration unit https://web.dev/articles/ta-strategies

Slide 18

Slide 18

“THE SHAPES” — THE CRAB 🦀 e2e integration & unit tests https://web.dev/articles/ta-strategies

Slide 19

Slide 19

“THE SHAPES” — THE DIAMOND e2e integration unit https://web.dev/articles/ta-strategies

Slide 20

Slide 20

“THE SHAPES” — THE DIAMOND e2e integration unit https://web.dev/articles/ta-strategies

Slide 21

Slide 21

“THE SHAPES” — THE HONEYCOMB e2e integration unit https://web.dev/articles/ta-strategies

Slide 22

Slide 22

WE ARE ABLE TO REFACTOR THE INTERNALS WITHOUT TOUCHING ANY TESTS. WE COULD EVEN REPLACE THE DATABASE FROM POSTGRESQL TO NOSQL WITHOUT HAVING TO MODIFY THE ACTUAL TEST METHODS. https://engineering.atspotify.com/2018/01/testing-of-microservices/

Slide 23

Slide 23

THE TRADE-OFF HERE IS SOME LOSS OF SPEED IN TEST EXECUTION [… AND …] THAT WE MIGHT LOSE SOME FEEDBACK ACCURACY WHEN A TEST FAILS https://engineering.atspotify.com/2018/01/testing-of-microservices/

Slide 24

Slide 24

“THE SHAPES” — THE TROPHY e2e integration unit static https://web.dev/articles/ta-strategies

Slide 25

Slide 25

https://twitter.com/searls/status/1393571227650908162

Slide 26

Slide 26

https://twitter.com/searls/status/1393385209089990659

Slide 27

Slide 27

PART II: Why do we write tests?

Slide 28

Slide 28

PART II: Why do we not write tests?

Slide 29

Slide 29

WHY DO WE NOT WRITE TESTS?

Slide 30

Slide 30

WHY DO WE NOT WRITE TESTS? “We don’t have time for this”

Slide 31

Slide 31

WHY DO WE NOT WRITE TESTS? “We don’t have time for this” “They start failing when changing unrelated code or implementation details and are becoming brittle quickly”

Slide 32

Slide 32

WHY DO WE DO WRITE TESTS?

Slide 33

Slide 33

WHY DO WE DO WRITE TESTS? “To make our managers or team lead happy”

Slide 34

Slide 34

ANY OBSERVED STATISTICAL REGULARITY WILL TEND TO COLLAPSE ONCE PRESSURE IS PLACED UPON IT FOR CONTROL PURPOSES — Goodhart’s Law https://www.ribbonfarm.com/2016/06/09/goodharts-law-and-why-measurement-is-hard/

Slide 35

Slide 35

WHY DO WE DO WRITE TESTS? “To make our managers or team lead happy”

Slide 36

Slide 36

WHY DO WE DO WRITE TESTS? “To make our managers or team lead happy” Stability for the end-user

Slide 37

Slide 37

“A MAJORITY OF THE PRODUCTION FAILURES (77%) CAN BE REPRODUCED BY A UNIT TEST.” — Simple testing can prevent most critical failures; Research paper from the University of Toronto (2014) https://www.usenix.org/system/files/conference/osdi14/osdi14-paper-yuan.pdf

Slide 38

Slide 38

WHY DO WE DO WRITE TESTS? “To make our managers or team lead happy” Stability for the end-user Enable refactoring

Slide 39

Slide 39

CODE IS READ AND UPDATED WAY MORE OFTEN THAN IT IS WRITTEN — Tim Bray https://www.tbray.org/ongoing/When/202x/2021/05/15/Testing-in-2021

Slide 40

Slide 40

“WALKING ON WATER AND DEVELOPING SOFTWARE FROM A SPECIFICATION ARE EASY IF BOTH ARE FROZEN” — Edward V. Berard https://en.wikiquote.org/wiki/Edward_V._Berar

Slide 41

Slide 41

PART III: a little d etour, sorry! TDD — The misunderstood monster under your bed

Slide 42

Slide 42

RED-GREEN-REFACTOR

Slide 43

Slide 43

RED-GREEN-REFACTOR Write a test that describes the desired behaviour https://tidyfirst.substack.com/p/canon-tdd

Slide 44

Slide 44

RED-GREEN-REFACTOR Write a test that describes the desired behaviour Write the minimal amount of code necessary to make the test pass https://tidyfirst.substack.com/p/canon-tdd

Slide 45

Slide 45

RED-GREEN-REFACTOR Write a test that describes the desired behaviour Write the minimal amount of code necessary to make the test pass Refactor the code https://tidyfirst.substack.com/p/canon-tdd

Slide 46

Slide 46

SELF-TESTING CODE

Slide 47

Slide 47

Slide 48

Slide 48

SELF-TESTING CODE Tests should be part of your code delivery https://martinfowler.com/distributedComputing/duckling.pdf

Slide 49

Slide 49

SELF-TESTING CODE Tests should be part of your code delivery You should be running tests as often as possible — ideally automated https://martinfowler.com/distributedComputing/duckling.pdf

Slide 50

Slide 50

TDD — SOME MISCONCEPTIONS

Slide 51

Slide 51

TDD — SOME MISCONCEPTIONS “TDD means I have to write my tests first!”

Slide 52

Slide 52

IS TDD DEAD? — VIDEO SERIES WITH DHH, MARTIN FOWLER AND KENT BECK https://martinfowler.com/articles/is-tdd-dead/

Slide 53

Slide 53

TDD — SOME MISCONCEPTIONS “TDD says I have to mock everything outside of the unit test scope”

Slide 54

Slide 54

“SIMILARLY THEIR NOTION OF INTEGRATION TEST SOUNDS VERY MUCH LIKE WHAT I WOULD CALL A SOCIABLE UNIT TEST. THIS MAKES THE PYRAMID VERSUS HONEYCOMB DISCUSSION MOOT” — Martin Fowler https://martinfowler.com/articles/2021-test-shapes.html

Slide 55

Slide 55

Slide 56

Slide 56

PART IV: Practical tips to get started with testing

Slide 57

Slide 57

1 Be the advocate!

Slide 58

Slide 58

2 Embrace tests as a way to improve developer confidence

Slide 59

Slide 59

3 Test behaviour, not implementation details

Slide 60

Slide 60

4 Automate your tests!

Slide 61

Slide 61

5 Identify the most common or likely points of failure in your system

Slide 62

Slide 62

ANOTHER APPLICATION OF CYCLOMATIC COMPLEXITY IS IN DETERMINING THE NUMBER OF TEST CASES THAT ARE NECESSARY TO ACHIEVE THOROUGH TEST COVERAGE OF A PARTICULAR MODULE. https://en.wikipedia.org/wiki/Cyclomatic_complexity

Slide 63

Slide 63

6 Don’t just blindly follow a “shape” or strategy

Slide 64

Slide 64

ENSURE YOUR “SHAPE” HAS INTENTION

Slide 65

Slide 65

ENSURE YOUR “SHAPE” HAS INTENTION let’s add the static la yer

Slide 66

Slide 66

ENSURE YOUR “SHAPE” HAS INTENTION m e t s y s eco e m o s s r e v o c s t s te

Slide 67

Slide 67

ENSURE YOUR “SHAPE” HAS INTENTION m e t s y s eco e m o s s r e v o c s t s te other “natur al” erosio n

Slide 68

Slide 68

7 Have smaller milestones to work towards the end goal

Slide 69

Slide 69

MILESTONES TO YOUR IDEAL SETUP manual testing

Slide 70

Slide 70

MILESTONES TO YOUR IDEAL SETUP quick & easy confid ence boost

Slide 71

Slide 71

MILESTONES TO YOUR IDEAL SETUP p u g n i d l i e r bu o c e h t

Slide 72

Slide 72

MILESTONES TO YOUR IDEAL SETUP

Slide 73

Slide 73

THE END. @jburr90 / Julian Burr https://www.julianburr.de/ ddd-melbourne-2024-slides.pdf

Slide 74

Slide 74

Proudly sponsored by MELBOURNE2024 Diamond Sponsors Platinum Sponsors Gold Sponsors Childcare by: Wi-Fi by: Coffee Cart by: Silver Sponsors

Slide 75

Slide 75

MELBOURNE 2024