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

Cosmic Ray: Mutation Test for Python

Cosmic Ray: Mutation Test for Python

The slides for the short talk I gave at the Learn Python NYC meetup on May 12, 2015.

abingham

May 12, 2015
Tweet

More Decks by abingham

Other Decks in Programming

Transcript

  1. @sixty_north Cosmic Ray: Mutation Testing for Python Who watches the

    watchers? 1 Austin Bingham @austin_bingham Wednesday, May 13, 15
  2. What is mutation testing? 2 Apply small changes to code

    Run test suite Wednesday, May 13, 15
  3. What is mutation testing? 2 Apply small changes to code

    Run test suite Test suite fails – KILLED Wednesday, May 13, 15
  4. What is mutation testing? 2 Apply small changes to code

    Run test suite Test suite fails – KILLED Test suite error – INCOMPETENT Wednesday, May 13, 15
  5. What is mutation testing? 2 Apply small changes to code

    Run test suite Test suite fails – KILLED Test suite error – INCOMPETENT Test suite passes – SURVIVED!!! Wednesday, May 13, 15
  6. What does mutation testing tell us? 3 Killed Tests properly

    detected the mutation. Wednesday, May 13, 15
  7. What does mutation testing tell us? 3 Killed Tests properly

    detected the mutation. Incompetent Mutation produced code which is inherently flawed. Wednesday, May 13, 15
  8. What does mutation testing tell us? 3 Killed Tests properly

    detected the mutation. Incompetent Mutation produced code which is inherently flawed. Survived Tests failed to detect the mutant! Wednesday, May 13, 15
  9. What does mutation testing tell us? 3 Killed Tests properly

    detected the mutation. Incompetent Mutation produced code which is inherently flawed. Survived Tests failed to detect the mutant! Tests are inadequate for detecting defects in necessary code either Wednesday, May 13, 15
  10. What does mutation testing tell us? 3 Killed Tests properly

    detected the mutation. Incompetent Mutation produced code which is inherently flawed. Survived Tests failed to detect the mutant! Tests are inadequate for detecting defects in necessary code either Mutated code is extraneous or Wednesday, May 13, 15
  11. Examples of mutations 5 Replace relational operator x > 1

    x < 1 break/continue replacement break continue Wednesday, May 13, 15
  12. Examples of mutations 5 • AOD - arithmetic operator deletion

    • AOR - arithmetic operator replacement • ASR - assignment operator replacement • BCR - break continue replacement • COD - conditional operator deletion • COI - conditional operator insertion • CRP - constant replacement • DDL - decorator deletion • EHD - exception handler deletion • EXS - exception swallowing • IHD - hiding variable deletion • IOD - overriding method deletion • IOP - overridden method calling position change • LCR - logical connector replacement • LOD - logical operator deletion • LOR - logical operator replacement • ROR - relational operator replacement • SCD - super calling deletion • SCI - super calling insert • SIR - slice index remove Replace relational operator x > 1 x < 1 break/continue replacement break continue Wednesday, May 13, 15
  13. Abstract syntax tree manipulation ast ‣ Identify nodes which can

    be manipulated ‣ Modify copies of ASTs using ast.NodeTransformer 8 Wednesday, May 13, 15
  14. Arrange for mutated ASTs to be imported importlib ‣ importlib.abc.MetaPathFinder

    ‣ sys.meta_path ‣ Loaders ‣ importlib.machinery.ModuleSpec 9 import turtle Wednesday, May 13, 15
  15. Mutant isolation with multiple processes multiprocessing 10 cosmic-ray Process 1

    Mutant 1 Process 2 Mutant 2 Process 3 Mutant 3 ‣ Avoid cross-mutant interference ‣ Significantly simplifies spawning processes Wednesday, May 13, 15