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

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

Play sponsor bingo and you can win MELBOURNE2024

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

PART I: Common testing methodologies

THE DIFFERENT TYPES OF TESTS

THE DIFFERENT TYPES OF TESTS

  1. Unit tests your smallest units of code

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

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

THE DIFFERENT TYPES OF TESTS

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

THE DIFFERENT TYPES OF TESTS

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

THE DIFFERENT TYPES OF TESTS

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

“THE SHAPES”

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

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

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

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

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

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

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

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

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/

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/

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

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

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

PART II: Why do we write tests?

PART II: Why do we not write tests?

WHY DO WE NOT WRITE TESTS?

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

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”

WHY DO WE DO WRITE TESTS?

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

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/

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

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

“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

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

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

“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

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

RED-GREEN-REFACTOR

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

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

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

SELF-TESTING CODE

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

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

TDD — SOME MISCONCEPTIONS

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

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

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

“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

PART IV: Practical tips to get started with testing

1 Be the advocate!

2 Embrace tests as a way to improve developer confidence

3 Test behaviour, not implementation details

4 Automate your tests!

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

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

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

ENSURE YOUR “SHAPE” HAS INTENTION

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

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

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

7 Have smaller milestones to work towards the end goal

MILESTONES TO YOUR IDEAL SETUP manual testing

MILESTONES TO YOUR IDEAL SETUP quick & easy confid ence boost

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

MILESTONES TO YOUR IDEAL SETUP

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

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

MELBOURNE 2024