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

Getting Started with Mutation Testing

Getting Started with Mutation Testing

A quick introduction to mutation testing in PHP with infection. This talk covers how to set up infection in a project, how to read the reports it generates and why mutation coverage might be more helpful than line coverage provided by phpunit. The talk closes with tips on how to improve performance as mutation testing will produce a test matrix that inevitably will be slower than the test suite its based upon.

Denis Brumann

May 18, 2020
Tweet

More Decks by Denis Brumann

Other Decks in Programming

Transcript

  1. Mutation testing involves modifying a program in small ways. If

    mutated program produces failing tests, this is called a killed mutant. If tests are green with mutated code, then we have an escaped mutant.
  2. Installation Phar, Phive, Composer, Git or Homebrew Infection requires a

    recent version of PHP, and XDebug, phpdbg, or pcov enabled.
  3. Mutators Exceptions Name Original Mutated Throw_ throw new \Exception new

    \Exception Finally_ try {} catch {} finally {} try {} catch {}
  4. Mutators Equal or Identical Checks Name Original Mutated EqualIdentical ==

    === NotEqualNotIdentical != !== IdenticalEqual === == NotIdenticalNotEqal !== !=
  5. Profiles { "source": { "directories": [ "src" ] }, "timeout":

    10, "logs": { "text": "infection.log" }, "mutators": { "@default": true, "@identical": true, } }
  6. Performance Only Changed Files CHANGED_FILES=$(git diff origin/master --diff-filter=AM --name-only |

    grep src/ | paste -sd "," -); INFECTION_FILTER="--filter=${CHANGED_FILES} --ignore-msi-with-no-mutations"; infection --threads=4 $INFECTION_FILTER
  7. Summary Cons Pros easy setup false positives mutation shows what

    to test for "better" coverage slow runs in CI + provides coverage report