Slide 1

Slide 1 text

Are Your Tests Slowing You Down? Trisha Gee

Slide 2

Slide 2 text

https://trishagee.com/books/

Slide 3

Slide 3 text

Tests Make You More Productive? Tests Make You More Productive

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

So it’s OK not to write tests, right?

Slide 7

Slide 7 text

“Testing is Xanax for programmers, it’s an anxiety reducing technique.” https://youtu.be/guycIP56YeY Kent Beck

Slide 8

Slide 8 text

What slows down your testing?

Slide 9

Slide 9 text

What slows down your testing?

Slide 10

Slide 10 text

What slows down your testing?

Slide 11

Slide 11 text

1. Writing 2. Troubleshooting 3. Running

Slide 12

Slide 12 text

1. Writing Tests Takes Time

Slide 13

Slide 13 text

Use Your IDE

Slide 14

Slide 14 text

AI Will Make You Super Productive

Slide 15

Slide 15 text

AI is good for generating mundane and/or predictable code

Slide 16

Slide 16 text

AI is good for generating test data

Slide 17

Slide 17 text

AI can consider edge cases we haven’t thought of

Slide 18

Slide 18 text

AI is a decent companion …but it doesn’t replace you

Slide 19

Slide 19 text

AI is a lying toad

Slide 20

Slide 20 text

“The keyboard is not the bottleneck.” Dave Farley

Slide 21

Slide 21 text

“The productivity myth suggests that anything we spend time on is up for automation…. The importance and value of thinking about our work and why we do it is waved away as a distraction. The goal of writing… is filling a page rather than the process of thought that a completed page represents.” https://www.techpolicy.press/challenging-the-myths-of-generative-ai/ Eryk Salvaggio

Slide 22

Slide 22 text

Bring a friend

Slide 23

Slide 23 text

“We recommend that the developers, who are good at writing efficient, maintainable code, work together with the testers, who are good at specifying test cases, to automate tests.” Agile Testing Condensed: A Brief Introduction Lisa Crispin, Janet Gregory

Slide 24

Slide 24 text

https://bit.ly/3RG85vc

Slide 25

Slide 25 text

“Creativity is a wild mind and a disciplined eye.” Dorothy Parker

Slide 26

Slide 26 text

Invest the time in writing to save time troubleshooting

Slide 27

Slide 27 text

2. Troubleshooting Takes Time

Slide 28

Slide 28 text

What is this test anyway?

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Your test needs to tell you what is expected and why, so you understand what to do when it fails.

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Why do tests fail? Body text

Slide 35

Slide 35 text

‣ Code is wrong ‣ Test is wrong

Slide 36

Slide 36 text

Something changed

Slide 37

Slide 37 text

• Production code • Test code • Refactoring/structure • Data • Infrastructure • Load or usage

Slide 38

Slide 38 text

1. Whose fault is it?

Slide 39

Slide 39 text

1. Triage

Slide 40

Slide 40 text

• Production code • Test code • Refactoring/structure • Data • Infrastructure • Load or usage

Slide 41

Slide 41 text

You need data

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

2. Fix it

Slide 46

Slide 46 text

“Your best and wisest refuge from all troubles is in your science.” Ada Lovelace

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

Data is key

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Tools for seeing more

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Automation is your friend

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Learn how to use your debugger!

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Aim for fast feedback and easy reproduction

Slide 63

Slide 63 text

“99.9% of the time the best way to troubleshoot a test is to re-write it so it’s smaller and faster.” Israel Boza Rodriguez (@IsraKaos)

Slide 64

Slide 64 text

Fixed! ✅

Slide 65

Slide 65 text

Let’s talk about “unreliable test results”

Slide 66

Slide 66 text

I have made the decision to trust you Body text

Slide 67

Slide 67 text

1. Find Your Flaky Tests

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

This is NOT a fix!

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

So now you can ignore those flaky tests

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

2. Quarantine your flaky tests

Slide 74

Slide 74 text

3. Fix your flaky tests!!!

Slide 75

Slide 75 text

If you add a new test and it’s flaky Or are working on a test and it becomes flaky Fix it now!!

Slide 76

Slide 76 text

1. When they impact you directly 2. Attach them to related functionality 3. Flaky Test Days 4. Add flaky tests to the backlog 5. 20% time, tech debt time, cleanup time… Make Time To Fix Flaky Tests

Slide 77

Slide 77 text

1. Environment, Network, and Resources 2. Integration Points 3. Concurrency, Asynchronous Programming, and Waiting 4. Setup/Teardown and Test Data 5. System Behaviour Causes of flakiness Known good practices and tools Not always in my control Try to minimise these Can be REALLY HARD

Slide 78

Slide 78 text

https://youtu.be/vHBzZHE4tJ0 1. Environment 2. Test Data 3. Versioning 4. Resource Use 5. System Behaviour

Slide 79

Slide 79 text

3. Running Tests Takes Time

Slide 80

Slide 80 text

What slows down your testing?

Slide 81

Slide 81 text

How do you speed up your tests?

Slide 82

Slide 82 text

Use a Build Cache

Slide 83

Slide 83 text

Very effective for multi-module projects

Slide 84

Slide 84 text

No cache: Full build required

Slide 85

Slide 85 text

Build cache: Changing a leaf module

Slide 86

Slide 86 text

Build cache: Changing a module’s implementation

Slide 87

Slide 87 text

Build cache: Changing core implementation

Slide 88

Slide 88 text

Remote Build Cache

Slide 89

Slide 89 text

Run tests in parallel (local)

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

Run tests in parallel (CI)

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

Test Distribution

Slide 94

Slide 94 text

Test Distributor

Slide 95

Slide 95 text

Test Distribution Results ‑ ~50% ‑ ~50% ‑ ~50% Doubling the number of executors cuts build time in half

Slide 96

Slide 96 text

Let’s use AI!

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

“The test selection procedure selects fewer than a third of the tests that would be selected on the basis of build dependencies” Predictive Test Selection - Meta Research https://research.facebook.com/publications/predictive-test-selection/ Mateusz Machalica, Alex Samylkin, Meredith Porth, Satish Chandra

Slide 99

Slide 99 text

Predictive Test Selection time savings

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

What if we just make our tests faster?

Slide 102

Slide 102 text

Like any performance problem, focus on the worst-performers first

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

No content

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

“Once things like databases become a hindrance, optimise the testing loop, mock things out to run things fast. You can run locally and you don't have all the same infra dependencies as someone else.” On DevEx, PaaS, and Testing in Production https://bit.ly/3ZA0uQM Kelsey Hightower

Slide 109

Slide 109 text

Look out for expensive setup and tear down

Slide 110

Slide 110 text

Invent Time Travel

Slide 111

Slide 111 text

Write Better Tests

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

⬢ Separation of concerns ⬢ Encapsulation ⬢ High cohesion and loose coupling ⬢ SOLID ⬢ DRY ⬢ Descriptive naming ⬢ Modularisation ⬢ Designing for performance

Slide 114

Slide 114 text

Tension between these ideals

Slide 115

Slide 115 text

Refactor and Delete

Slide 116

Slide 116 text

“Yes, I regularly delete tests that no longer add unique value.” Angie Jones (@techgirl1908)

Slide 117

Slide 117 text

Summary

Slide 118

Slide 118 text

Automate as much as possible

Slide 119

Slide 119 text

Tooling can help you

Slide 120

Slide 120 text

There is a time investment in writing tests, because there should be thinking involved

Slide 121

Slide 121 text

Invest time in writing better tests. They will be easier to debug, less flaky, and better document your system’s expected behaviour

Slide 122

Slide 122 text

“Testing is not only for checking the system does what it’s supposed to, it’s for documenting the expected behaviour.” Israel Boza Rodriguez (@IsraKaos)

Slide 123

Slide 123 text

bit.ly/3MGAMnZ bit.ly/slow-tests Win a copy of Getting to Know IntelliJ IDEA!