Slide 1

Slide 1 text

Trisha Gee Head of Developer Advocacy, Gradle Are Your Tests Slowing You Down?

Slide 2

Slide 2 text

● Head of Developer Advocacy at Gradle ● Java Champion & JetBrains Community Contributor ● 20+ years development experience ● Author & YouTuber Trisha Gee

Slide 3

Slide 3 text

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? Writing tests Running tests locally Running tests in CI Troubleshooting tests Unreliable test results

Slide 9

Slide 9 text

1. Writing 2. Troubleshooting 3. Running

Slide 10

Slide 10 text

1. Writing Tests Takes Time

Slide 11

Slide 11 text

Use Your IDE

Slide 12

Slide 12 text

AI Will Make You Super Productive

Slide 13

Slide 13 text

AI is good for generating mundane or predictable code

Slide 14

Slide 14 text

AI is good for generating test data

Slide 15

Slide 15 text

AI can consider edge cases we haven’t thought of

Slide 16

Slide 16 text

AI can test what’s there. It can’t tell you how the system should behave

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

The keyboard is not the bottleneck.” Dave Farley

Slide 19

Slide 19 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.” https://www.techpolicy.press/challenging-the-myths-of-generative-ai/ Eryk Salvaggio

Slide 20

Slide 20 text

Bring a friend

Slide 21

Slide 21 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 22

Slide 22 text

https://bit.ly/3RG85vc

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Invest the time in writing to save time troubleshooting

Slide 25

Slide 25 text

2. Troubleshooting Takes Time

Slide 26

Slide 26 text

What slows down your testing? Writing tests Running tests locally Running tests in CI Troubleshooting tests Unreliable test results

Slide 27

Slide 27 text

What is this test anyway?

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Why do tests fail? Body text

Slide 33

Slide 33 text

‣ Code is wrong ‣ Test is wrong

Slide 34

Slide 34 text

Something changed

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

1. Whose fault is it?

Slide 37

Slide 37 text

1. Triage

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

You need data

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

2. Fix it

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Learn how to use your debugger!

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Aim for fast feedback and easy reproduction

Slide 57

Slide 57 text

Fixed! ✅

Slide 58

Slide 58 text

What slows down your testing? Writing tests Running tests locally Running tests in CI Troubleshooting tests Unreliable test results

Slide 59

Slide 59 text

“Unreliable test results”

Slide 60

Slide 60 text

I have made the decision to trust you Body text

Slide 61

Slide 61 text

1. Find Your Flaky Tests

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

This is not a fix!

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

So now you can ignore those flaky tests

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

2. Quarantine your flaky tests

Slide 69

Slide 69 text

3. Fix your flaky tests!!!

Slide 70

Slide 70 text

If you add a new test and it’s flaky

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

If you add a new test and it’s flaky Or are working on a test and it becomes flaky Fix it now!! (Future you will thank you)

Slide 73

Slide 73 text

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

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

3. Running Tests Takes Time

Slide 77

Slide 77 text

What slows down your testing? Writing tests Running tests locally Running tests in CI Troubleshooting tests Unreliable test results

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

Use a Build Cache

Slide 80

Slide 80 text

Spring Boot Build Times

Slide 81

Slide 81 text

Very effective for multi-module projects

Slide 82

Slide 82 text

No cache: Full build required

Slide 83

Slide 83 text

Build cache: Changing a module’s implementation

Slide 84

Slide 84 text

Remote Build Cache

Slide 85

Slide 85 text

Run tests in parallel (local)

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

Run tests in parallel (CI)

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

Test Distribution

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

Let’s use AI!

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 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 95

Slide 95 text

Predictive Test Selection time savings

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

What if we just make our tests faster?

Slide 98

Slide 98 text

Like any performance problem, focus on the worst first

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 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 105

Slide 105 text

Look out for expensive setup and tear down

Slide 106

Slide 106 text

Invent Time Travel

Slide 107

Slide 107 text

Write Better Tests

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

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

Slide 110

Slide 110 text

Tension between these ideals

Slide 111

Slide 111 text

Refactor and Delete

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

In Summary

Slide 114

Slide 114 text

Automate as much as possible

Slide 115

Slide 115 text

Tooling can help you

Slide 116

Slide 116 text

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

Slide 117

Slide 117 text

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

Slide 118

Slide 118 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 119

Slide 119 text

Thank you! bit.ly/slow-tests tinyurl.com/dv-trial

Slide 120

Slide 120 text

No content