Slide 1

Slide 1 text

Getting Started With Mutation Testing Denis Brumann [email protected]

Slide 2

Slide 2 text

Denis Brumann @dbrumann [email protected]

Slide 3

Slide 3 text

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.

Slide 4

Slide 4 text

Installation Phar, Phive, Composer, Git or Homebrew Infection requires a recent version of PHP, and XDebug, phpdbg, or pcov enabled.

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Demo

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Mutators Boolean Substitution Name Original Mutated TrueValue true false FalseValue - + LogicalAnd && || LogicalOr || &&

Slide 12

Slide 12 text

Mutators Literal Numbers Name Original Mutated OneZeroInteger 0 1 ZeroOneInteger 1 0 DecrementInteger 7 6 IncrementInteger 7 8

Slide 13

Slide 13 text

Mutators Binary Arithmetic Name Original Mutated Plus + - Minus - + AssignmentEqual == =

Slide 14

Slide 14 text

Mutators Exceptions Name Original Mutated Throw_ throw new \Exception new \Exception Finally_ try {} catch {} finally {} try {} catch {}

Slide 15

Slide 15 text

Mutators Equal or Identical Checks Name Original Mutated EqualIdentical == === NotEqualNotIdentical != !== IdenticalEqual === == NotIdenticalNotEqal !== !=

Slide 16

Slide 16 text

Profiles { "source": { "directories": [ "src" ] }, "timeout": 10, "logs": { "text": "infection.log" }, "mutators": { "@default": true, "@identical": true, } }

Slide 17

Slide 17 text

More Demo

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

vendor/bin/infection --only-covered Performance Only Covered

Slide 20

Slide 20 text

Performance Disable Filters { "mutators": { "@default": true, "Plus": false, } }

Slide 21

Slide 21 text

Summary Cons Pros easy setup false positives mutation shows what to test for "better" coverage slow runs in CI + provides coverage report