Slide 1

Slide 1 text

mutation testing elixir in Daniel Serrano 2019

Slide 2

Slide 2 text

outline • what is mutation testing? • exavier • elixir AST • exunit • mutators • biggest drawback • rough edges • future

Slide 3

Slide 3 text

mutation testing who watches the watchmen?

Slide 4

Slide 4 text

mutation testing who tests the tests?

Slide 5

Slide 5 text

mutation testing ✨ mutation testing ✨

Slide 6

Slide 6 text

DeMillo, Lipton and Sayward 1978 mutation testing

Slide 7

Slide 7 text

1. write green tests 2. modify code under test 3. check tests now fail 1. 2. 3. code test code test code test mutation testing

Slide 8

Slide 8 text

• killed mutant test fails after mutation (expected, good) code mutation testing test

Slide 9

Slide 9 text

• surviving mutant test stays green after mutation (unexpected, bad) code test mutation testing

Slide 10

Slide 10 text

• threshold mutation testing cover threshold percentage of killed mutants below which mutation testing fails (e.g., 80%) mutation testing

Slide 11

Slide 11 text

• elixir mutation testing library • goal • install exavier library • run mix exavier.test • mutate code • run tests • show mutation testing report exavier

Slide 12

Slide 12 text

how tho?

Slide 13

Slide 13 text

elixir AST

Slide 14

Slide 14 text

elixir AST * + 3 1 2 abstract syntax tree tree representation of the abstract syntactic structure of the source code (1+2) * 3

Slide 15

Slide 15 text

elixir AST * + 3 1 2 (1+2) * 3 {:*, [line: 1], [ {:+, [line: 1], [ 1, 2 ]}, 3 ]}

Slide 16

Slide 16 text

elixir AST * + 3 1 2 (1+2) * 3 {:*, [line: 1], [ {:+, [line: 1], [ 1, 2 ]}, 3 ]}

Slide 17

Slide 17 text

elixir AST * + 3 1 2 (1+2) * 3 {:*, [line: 1], [ {:+, [line: 1], [ 1, 2 ]}, 3 ]}

Slide 18

Slide 18 text

elixir AST * + 3 1 2 (1+2) * 3 {:*, [line: 1], [ {:+, [line: 1], [ 1, 2 ]}, 3 ]}

Slide 19

Slide 19 text

elixir AST * + 3 1 2 {:*, [line: 1], [ {:+, [line: 1], [ 1, 2 ]}, 3 ]} operator metadata arguments

Slide 20

Slide 20 text

elixir AST {atom, keyword, list} operator metadata arguments

Slide 21

Slide 21 text

• ast.ninja • Kernel.quote/2 demo • Code.string_to_quoted/2 • Code.compile_quoted/2

Slide 22

Slide 22 text

elixir AST Arjan Scherpenisse – AST ninja

Slide 23

Slide 23 text

• elixir mutation testing library • goal • install exavier library • run mix exavier.test • mutate code • run tests • show mutation testing report exavier

Slide 24

Slide 24 text

exunit

Slide 25

Slide 25 text

exunit • default elixir testing framework • mix task mix test

Slide 26

Slide 26 text

exunit

Slide 27

Slide 27 text

exunit

Slide 28

Slide 28 text

• elixir mutation testing library • goal • install exavier library • run mix exavier.test • mutate code • run tests • show mutation testing report exavier

Slide 29

Slide 29 text

exunit • allows definition of custom formatters • provides callbacks for events •:test_started •:test_finished • etc. • e.g., junit_formatter

Slide 30

Slide 30 text

exunit

Slide 31

Slide 31 text

• elixir mutation testing library • goal • install exavier library • run mix exavier.test • mutate code • run tests • show mutation testing report exavier

Slide 32

Slide 32 text

mutators • used by pitest (JVM) and mutant (Ruby) • e.g., following pitest, AOR1 (Arithmetic Operator Replacement Mutator #1) original mutated + - - + * / / * % *

Slide 33

Slide 33 text

mutators

Slide 34

Slide 34 text

mutators • e.g., following pitest, REMOVE_CONDITIONALS (Remove Conditionals Mutator) “The remove conditionals mutator will remove all conditionals statements such that the guarded statements always execute” original mutated

Slide 35

Slide 35 text

mutators • e.g., following pitest, REMOVE_CONDITIONALS (Remove Conditionals Mutator) “The remove conditionals mutator will remove all conditionals statements such that the guarded statements always execute” original mutated

Slide 36

Slide 36 text

mutators

Slide 37

Slide 37 text

we’re ready

Slide 38

Slide 38 text

exavier • Run code line coverage analysis for each module, sequentially • Mutate the code according to each available mutator For each module, in parallel: For each mutator, sequentially: 1. Mutate code with given mutator 2. Run tests (now against mutated code) 3. Report (% mutants survived vs. killed)

Slide 39

Slide 39 text

exavier •mix exavier.test

Slide 40

Slide 40 text

biggest drawback • currently mutating a single module all at once and running all tests against mutated module problem?

Slide 41

Slide 41 text

biggest drawback • skews number of survived mutants, e.g.:

Slide 42

Slide 42 text

rough edges • Macros • might be hard to provide useful output • may have to track macro expansion (if possible) • Edge cases, e.g.: • division by zero (Issue #7) • function references as division (Issue #2)

Slide 43

Slide 43 text

future • get back to work on exavier • hopefully with the help of the community ⚠ first order of business: fix “biggest drawback”

Slide 44

Slide 44 text

the end thank you questions? dnlserrano.dev