Slide 1

Slide 1 text

UNIT TESTING BEYOND

Slide 2

Slide 2 text

THE PYRAMID OF TESTS HAVE YOU SEEN THIS IMAGE BEFORE? ▸ Common knowledge? ▸ Some say that it means that you should write more unit tests than any other type ▸ Another interpretation is that unit tests are faster, and cheaper

Slide 3

Slide 3 text

MOST UNIT TESTING IS WASTE? WHAT IF I TELL YOU

Slide 4

Slide 4 text

ABOUT HOW WE UNIT TEST LET’S BE HONEST

Slide 5

Slide 5 text

LET’S BE HONEST ABOUT HOW WE UNIT TEST WE ONLY TEST PARTIAL VALUES ▸ It would be impossible to test every possible output with every combination of the environment ▸ The combinatory of all those possibilities can easily go up to trillions of things to test

Slide 6

Slide 6 text

LET’S BE HONEST ABOUT HOW WE UNIT TEST WE THINK COVERING ALL LINES IS ENOUGH ▸ Covering all lines is not enough, because not all possible combinations are covered ▸ We like to trick the system by breaking functions to smaller pieces so we can cover all the lines ▸ This makes certain functions or classes more difficult to read

Slide 7

Slide 7 text

LET’S BE HONEST ABOUT HOW WE UNIT TEST WE WOULD RATHER NOT THINK ▸ We find workarounds to make tests pass ▸ If a failing test does not match our understanding, we just change it so that it passes

Slide 8

Slide 8 text

LET’S BE HONEST ABOUT HOW WE UNIT TEST TESTS ARE ALSO CODE ▸ Code needs to maintained ▸ Code contains bug ▸ Tests are code ▸ Your tests need maintenance and also have bugs ▸ Many changes in code need coordinated changes in tests ▸ In many code bases there are more lines of tests than application code

Slide 9

Slide 9 text

BE HUMBLE ABOUT WHAT YOUR UNIT TESTS CAN ACHIEVE James Coplien LET’S BE HONEST ABOUT HOW WE UNIT TEST

Slide 10

Slide 10 text

WITH CONFIDENCE HOW CAN WE REDUCE WASTE

Slide 11

Slide 11 text

REDUCING WASTE WITH CONFIDENCE FOCUS ON INFORMATION AND RISK ▸ Unit tests are meant to reduce the risk of deploying bad code in production ▸ You need information in order to reduce risk ▸ Tests that never fail are not contributing any information

Slide 12

Slide 12 text

DELETE TESTS THAT HAVE NOT FAILED IN A YEAR, MAINTAINING THEM IS COSTLIER James Coplien REDUCING WASTE WITH CONFIDENCE

Slide 13

Slide 13 text

TYPE A QUOTE HERE. DELETE TESTS THAT ONLY TEST THE OBVIOUS

Slide 14

Slide 14 text

TYPE A QUOTE HERE. DELETE TESTS THAT DON’T BREAK AFTER CHANGING THE BEHAVIOUR OF THE CODE THEY TEST

Slide 15

Slide 15 text

TYPE A QUOTE HERE. DELETE TESTS THAT FAIL AND YOU CANNOT UNDERSTAND THE BUSINESS VALUE THEY PROVIDE

Slide 16

Slide 16 text

THE BULK OF UNITS TEST SHOULD BE FOR ALGORITHMS WHERE THERE IS AN INDEPENDENT ORACLE FOR SUCCESS James Coplien REDUCING WASTE WITH CONFIDENCE

Slide 17

Slide 17 text

CONVERT UNIT TESTS TO ASSERTIONS

Slide 18

Slide 18 text

HAVE MORE INTEGRATION AND SYSTEM TESTS

Slide 19

Slide 19 text

WRITE THE DOCUMENTATION BEFORE YOU IMPLEMENT

Slide 20

Slide 20 text

USE PHPSTAN AND PSALM MANY UNIT TESTS CAN BE REPLACED BY BETTER TYPING