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

Go 100% Code Coverage or Go Home

Go 100% Code Coverage or Go Home

A look at what 100% code coverage is, and why it's important.

Presented at Glasgow PHP on 11th July, 2017.

Stuart Herbert

July 11, 2017
Tweet

More Decks by Stuart Herbert

Other Decks in Programming

Transcript

  1. @GanbaroDigital “With 100% code coverage, you could still ship bugs.

    Without 100% code coverage, you’re definitely shipping bugs.
  2. @GanbaroDigital In This Talk 1. What is Code Coverage? 2.

    What does it tell us? 3. What can’t it tell us? 4. How can we mitigate that? 5. Why does Code Coverage matter?
  3. @GanbaroDigital Code coverage measures: the lines of code in your

    unit under test that were executed when you ran your tests
  4. @GanbaroDigital Code coverage measures: the lines of code in your

    unit under test that were executed when you ran your tests
  5. @GanbaroDigital Code coverage measures: the lines of code in your

    unit under test that were executed when you ran your tests
  6. @GanbaroDigital Use code coverage annotations to tell PHPUnit what part(s)

    of your unit under test you are actually testing.
  7. @GanbaroDigital Code coverage measures: the lines of code in your

    unit under test that were executed when you ran your tests
  8. @GanbaroDigital Just because we live in times where science and

    engineering are out of vogue, doesn’t mean we have to pander to the forces of ignorance.
  9. @GanbaroDigital Code Coverage Does Not • Prove that all possible

    paths have tests • Prove that we’re testing the right things
  10. @GanbaroDigital Code Coverage Does Not • Prove that all possible

    paths have tests • Prove that we’re testing the right things
  11. @GanbaroDigital “With 100% code coverage, you could still ship bugs.

    Without 100% code coverage, you’re definitely shipping bugs.
  12. @GanbaroDigital Don’t think in terms of lines of code. Think

    in terms of behaviours and responsibilities.
  13. @GanbaroDigital “With 100% code coverage, you could still ship bugs.

    Without 100% code coverage, you’re definitely shipping bugs.
  14. @GanbaroDigital “ With 100% behaviour coverage, you’ll rarely ship bugs.

    Without 100% behaviour coverage, you’re definitely shipping bugs.
  15. @GanbaroDigital Code Coverage Does Not • Prove that all possible

    paths have tests • Prove that we’re testing the right things
  16. @GanbaroDigital Summary 1. Code coverage proves code runs. 2. Test

    behaviours, not code. 3. Use humans to check what you’re testing. 4. Use standards to guide your tests.
  17. @GanbaroDigital ?? ?? How many bugs have your tests found

    in the 60% of the code that you have tests for?
  18. @GanbaroDigital ?? ?? Why would the defect rate be any

    different in the remaining 40% of uncovered code?
  19. @GanbaroDigital Defect rate alone doesn’t tell the whole story. Not

    all defects cost the same when things go wrong.
  20. @GanbaroDigital The rule of thumb is that it costs 10x

    more to fix a defect at the next stage.
  21. @GanbaroDigital 10x programmers are real. They’re just folks who ship

    quickly whilst consistently reduce and avoid costly rework.