Roam Notes on “RailsConf 2017: How to Write Better Code Using Mutation Testing” by John Backus

  • "Author::" [[John Backus]]
  • "Source::" [[YouTube]]
  • "Recommended By::" [[John Backus]]
  • "Tags::" #programming #testing #Videos
  • "Roam Notes URL::" https://www.marknagelberg.com/roam-notes-on-railsconf-2017-how-to-write-better-code-using-mutation-testing-by-john-backus/
  • "Anki Tag::" backus_mutation_testing
  • "Anki Deck Link::" link
  • {{[video]: https://www.youtube.com/watch?v=uB7m9T7ymn8&feature=emb_title}}
  • Overview
    • [[John Backus]] gives an overview of [[mutation testing]] and why you should use it.
  • Introduction #Ankified
    • Line Coverage Formula = Lines of Code run by Test / Total Lines of code in the Project
    • Mutation Coverage: How much of your code can I change without breaking your tests?
      • If you can remove a line of code or meaningfully change the code without breaking a test, something is probably wrong: you’re missing a test or it’s dead code.
  • Benefits of [[mutation testing]]:
    • Learning about your programming language and the code you rely on
      • Mutation testing frameworks have many special case mutations baked into the tool that you likely wouldn’t think of on your own. They teach you things about your language and the code you rely on, and you learn about them just-in-time.
      • It makes you a better developer: "Mutation testing has been the most powerful source of growth for me in the past few years"
      • You not only learn more about the code, but you learn faster. The feedback loop is fast, and you learn more per unit of time spent coding.
    • Ship code with fewer bugs
      • Introduce fewer regressions to code, since it lets you see hotspots where you could break the code without failing the test, resulting in a bug that you would only find in production. #Ankified
      • It teaches you better testing skills – it forces you to think more about different conditions that can happen and the expected behaviour of your code.
    • X-Raying Legacy Code #[[legacy]]
      • Helps you find hot spots in legacy code, where you could potentially introduce a regression and the tests won’t fail. It gives you a checklist, and in each case you determine if you should change your tests or your code.
    • Dead Code Detection
      • Dead Code: code that is never executed, or when executed has no effect on the program. #Ankified
      • Often shows you’re using redundant code, without consulting programming language’s documentation or coworkers.
    • Better Test Coverage
  • Is it Practical? (30:15) #Ankified
    • You might be wondering – I open PRs that are hundreds of lines long and my tests take hours to run. How is this practical?
    • You can run mutation test only on code that has changed since a specified Git revision.
    • You can specify a particular method you want to run the mutation tests on.
  • Mutation Testing on the Job
    • You should run mutation tests before you push code. You’ll learn more, write better code, and grow faster than your colleagues that refuse to use it.
    • If you’re a team lead, incorporate mutation tests into [[continuous integration]]. You don’t need 100% mutation coverage to benefit.

For access to my shared Anki deck and Roam Research notes knowledge base as well as regular updates on tips and ideas about spaced repetition and improving your learning productivity, join “Download Mark’s Brain”.

For access to my shared Anki deck and Roam Research notes knowledge base as well as regular updates on tips and ideas about spaced repetition and improving your learning productivity, join "Download Mark's Brain".

Leave a Reply

Your email address will not be published. Required fields are marked *