Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Beyond Unit Testing

Beyond Unit Testing

José Lorenzo Rodríguez

November 05, 2019
Tweet

More Decks by José Lorenzo Rodríguez

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. BE HUMBLE ABOUT WHAT YOUR UNIT TESTS CAN ACHIEVE James

    Coplien LET’S BE HONEST ABOUT HOW WE UNIT TEST
  7. 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
  8. DELETE TESTS THAT HAVE NOT FAILED IN A YEAR, MAINTAINING

    THEM IS COSTLIER James Coplien REDUCING WASTE WITH CONFIDENCE
  9. TYPE A QUOTE HERE. DELETE TESTS THAT DON’T BREAK AFTER

    CHANGING THE BEHAVIOUR OF THE CODE THEY TEST
  10. TYPE A QUOTE HERE. DELETE TESTS THAT FAIL AND YOU

    CANNOT UNDERSTAND THE BUSINESS VALUE THEY PROVIDE
  11. THE BULK OF UNITS TEST SHOULD BE FOR ALGORITHMS WHERE

    THERE IS AN INDEPENDENT ORACLE FOR SUCCESS James Coplien REDUCING WASTE WITH CONFIDENCE