Testing Your Testing Strategy

A presentation at Revo.js in October 2023 in Timișoara, Romania by Trent Willis

Slide 1

Slide 1

Testing your testing strategy Trent Willis revo.js

Slide 2

Slide 2

Testing your testing strategy

cd existing-product Trent Willis revo.js

Slide 3

Slide 3

Testing your testing strategy

cd existing-product > init new-product Trent Willis revo.js

Slide 4

Slide 4

Testing your testing strategy

cd existing-product > init new-product > npm test Trent Willis revo.js

Slide 5

Slide 5

Testing your testing strategy

cd existing-product > init new-product > npm test Running… Trent Willis revo.js

Slide 6

Slide 6

Testing your testing strategy “ Trent Willis Why do I need to write tests when I might have to rewrite them in a few weeks anyway? revo.js

Slide 7

Slide 7

Testing your testing strategy “ Trent Willis This approach worked for the other project. We can’t ship features without tests! revo.js

Slide 8

Slide 8

Testing your testing strategy Trent Willis revo.js

Slide 9

Slide 9

Rethinking Testing your testing strategy Trent Willis revo.js

Slide 10

Slide 10

Testing your testing strategy Trent Willis Staff Software Engineer, Netflix Former QUnit project lead @trentmwillis Trent Willis revo.js

Slide 11

Slide 11

Testing your testing strategy Expectation vs. Reality of Testing Trent Willis revo.js

Slide 12

Slide 12

Testing your testing strategy Many applications remain under-tested* even though testing is widely regarded as a best practice *according to their authors Trent Willis revo.js

Slide 13

Slide 13

Testing your testing strategy Why testing feels inefficient Trent Willis revo.js

Slide 14

Slide 14

Testing your testing strategy Why testing feels inefficient: 1. Unnecessarily high expectations Trent Willis revo.js

Slide 15

Slide 15

Testing your testing strategy Popular testing wisdom advocates for multi-layered approaches for all projects Trent Willis revo.js

Slide 16

Slide 16

Testing your testing strategy There is an (over)abundance of testing options Trent Willis revo.js

Slide 17

Slide 17

Testing your testing strategy Why testing feels inefficient: 1. Unnecessarily high expectations 2. Underdeveloped skills Trent Willis revo.js

Slide 18

Slide 18

Testing your testing strategy Learning to write good (i.e., efficient and helpful) tests is a skill that must be developed Trent Willis revo.js

Slide 19

Slide 19

Testing your testing strategy Why testing feels inefficient: 1. Unnecessarily high expectations 2. Underdeveloped skills 3. Unhelpful tests Trent Willis revo.js

Slide 20

Slide 20

Testing your testing strategy const submitButton = screen.getByText(‘Submit’); expect(submitButton) .not.toHaveAttribute(‘disabled’); // Oops, submitButton is <span> not <button>! // So the test never fails! Trent Willis revo.js

Slide 21

Slide 21

Testing your testing strategy Why testing feels inefficient: 1. Unnecessarily high expectations 2. Underdeveloped skills 3. Unhelpful tests Trent Willis revo.js

Slide 22

Slide 22

Testing your testing strategy The value of testing is in quality not quantity Trent Willis revo.js

Slide 23

Slide 23

Testing your testing strategy How do you create a valuable testing strategy? Trent Willis revo.js

Slide 24

Slide 24

Testing your testing strategy Start by defining your goals Trent Willis revo.js

Slide 25

Slide 25

Testing your testing strategy Requirements met Trent Willis revo.js

Slide 26

Slide 26

Testing your testing strategy Time Trent Willis revo.js

Slide 27

Slide 27

Testing your testing strategy The best way to not break an application is to not change it, but we change software to make it better Trent Willis revo.js

Slide 28

Slide 28

Testing your testing strategy Iteration Speed vs. Confidence Trent Willis revo.js

Slide 29

Slide 29

Testing your testing strategy Confidence “No deploy Fridays” “Move fast and break things” Iteration Speed Trent Willis revo.js

Slide 30

Slide 30

Confidence Testing your testing strategy Time Spent On Testing Trent Willis revo.js

Slide 31

Slide 31

Testing your testing strategy The goal of a testing strategy should be to optimize the amount of confidence you get for the time you invest in testing Trent Willis revo.js

Slide 32

Slide 32

Testing your testing strategy How much confidence do you need? Trent Willis revo.js

Slide 33

Slide 33

Testing your testing strategy How much confidence do you need? 1. What stage of development are you in? 2. What are your users’ expectations? 3. What are the market expectations? Trent Willis revo.js

Slide 34

Slide 34

Testing your testing strategy How much confidence do you need? 1. What stage of development are you in? 2. What are your users’ expectations? 3. What are the market expectations? Trent Willis revo.js

Slide 35

Slide 35

Testing your testing strategy As a product “matures”, you need more confidence Trent Willis revo.js

Slide 36

Slide 36

Testing your testing strategy Your confidence level should mirror your confidence that requirements are stable Trent Willis revo.js

Slide 37

Slide 37

Testing your testing strategy How much confidence do you need? 1. What stage of development are you in? 2. What are your users’ expectations? 3. What are the market expectations? Trent Willis revo.js

Slide 38

Slide 38

Testing your testing strategy The cost to access and criticality of a product are directly related to how much confidence you need Trent Willis revo.js

Slide 39

Slide 39

Testing your testing strategy You can codify user expectations with service-level agreements (SLAs) Trent Willis revo.js

Slide 40

Slide 40

Testing your testing strategy How much confidence do you need? 1. What stage of development are you in? 2. What are your users’ expectations? 3. What are the market expectations? Trent Willis revo.js

Slide 41

Slide 41

Testing your testing strategy Good understanding of your product market expectations avoids over- or under-investing in your testing strategy Trent Willis revo.js

Slide 42

Slide 42

Testing your testing strategy Example Early development stage + Low user expectations + New market space = Iteration Speed > Confidence Trent Willis revo.js

Slide 43

Slide 43

Testing your testing strategy Evaluate your options for building confidence Trent Willis revo.js

Slide 44

Slide 44

Testing your testing strategy Non-Testing Options Trent Willis revo.js

Slide 45

Slide 45

Testing your testing strategy Non-Testing Options Static Analysis Trent Willis Linting Type checking revo.js

Slide 46

Slide 46

Testing your testing strategy Non-Testing Options Static Analysis Ideological Changes Trent Willis Reduce size + complexity Encapsulation SOLID (Single Responsibility) Presentational + Container revo.js

Slide 47

Slide 47

Testing your testing strategy Non-Testing Options Static Analysis Ideological Changes Processes Trent Willis Code reviews Easy + fast deployments Canaries / AB Tests Observability + monitoring revo.js

Slide 48

Slide 48

Testing your testing strategy Non-Testing Options Static Analysis Ideological Changes Processes Trent Willis revo.js

Slide 49

Slide 49

Testing your testing strategy Non-Testing Options can build confidence without significantly impacting iteration speed, especially with changing requirements Trent Willis revo.js

Slide 50

Slide 50

Testing your testing strategy “Actual” Tests Unit, end-to-end, integration, smoke, acceptance, regression, functional, behavioral, etc. Trent Willis revo.js

Slide 51

Slide 51

Testing your testing strategy Tests that validate a user flow end-to-end Tests that validate an isolated unit of functionality Trent Willis revo.js

Slide 52

Slide 52

Testing your testing strategy end-to-end tests Trent Willis unit tests revo.js

Slide 53

Slide 53

Testing your testing strategy end-to-end tests Mimic user flow Complicated, slow, flakey Confidence a user flow works Trent Willis unit tests revo.js

Slide 54

Slide 54

Testing your testing strategy end-to-end tests Mimic user flow Complicated, slow, flakey Confidence a user flow works Trent Willis unit tests Isolated functionality Simple, fast, stable No guarantee user flow works revo.js

Slide 55

Slide 55

Testing your testing strategy end-to-end tests Mimic user flow Complicated, slow, flakey Confidence a user flow works Trent Willis unit tests Isolated functionality Simple, fast, stable No guarantee user flow works revo.js

Slide 56

Slide 56

Testing your testing strategy Ideally, end-to-end tests are more valuable Really, unit tests are often a better value Trent Willis revo.js

Slide 57

Slide 57

Testing your testing strategy Doing one or the other well is better than doing both poorly Trent Willis revo.js

Slide 58

Slide 58

Testing your testing strategy Valuable tests are those that catch issues Trent Willis revo.js

Slide 59

Slide 59

Testing your testing strategy Confidence 100% Unit Tests End-to-End Tests Non-Testing Time Investment Trent Willis revo.js

Slide 60

Slide 60

Testing your testing strategy Put it all together Trent Willis revo.js

Slide 61

Slide 61

Testing your testing strategy Iteration Speed > Confidence What can you do within the time constraints? Trent Willis revo.js

Slide 62

Slide 62

Testing your testing strategy Ex: Barely enough time to deliver product as-is Static analysis (linting + type checking) Processes (fast deployments) Add unit/end-to-end tests later Trent Willis revo.js

Slide 63

Slide 63

Testing your testing strategy Ex: In between Alpha and Beta phases Ideological changes (refactor monolithic modules) Add unit tests for complex data logic Trent Willis revo.js

Slide 64

Slide 64

Testing your testing strategy Confidence > Iteration Speed What options give us the confidence needed? Trent Willis revo.js

Slide 65

Slide 65

Testing your testing strategy Ex: Read-only app End-to-end (visual regression) tests Static analysis (linting + type checking) Trent Willis revo.js

Slide 66

Slide 66

Testing your testing strategy Ex: Highly configurable dashboard app Unit tests (covering every option) End-to-end tests (for basic combinations of options) Ideological changes (small modules) Processes (fast deployments, code reviews) Static analysis (linting + type checking) Trent Willis revo.js

Slide 67

Slide 67

Testing your testing strategy Balance your time investment with the level of confidence you need at a given period in time Trent Willis revo.js

Slide 68

Slide 68

Testing your testing strategy Strategy should be revisited periodically Trent Willis revo.js

Slide 69

Slide 69

Testing your testing strategy Your mix of choices can/should change over time Trent Willis revo.js

Slide 70

Slide 70

Testing your testing strategy TL;DL (Too Long; Didn’t Listen) Trent Willis revo.js

Slide 71

Slide 71

Testing your testing strategy TL;DL (Too Long; Didn’t Listen) Define your goals Evaluate your options Make choices based on your goals Trent Willis revo.js

Slide 72

Slide 72

Testing your testing strategy A custom testing strategy benefits your users, company, and team Trent Willis revo.js

Slide 73

Slide 73

Testing your testing strategy You don’t need to reinvent the wheel, but you also don’t need to use the same wheels as everyone else Trent Willis revo.js