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

Mutation Tests - Joseph Yeo - Agile SG 2013

Mutation Tests - Joseph Yeo - Agile SG 2013

Presented in Agile Singapore 2013 Conference

66a1bb94b08fe5dcd07635a59681626c?s=128

Agile Singapore

November 08, 2013
Tweet

More Decks by Agile Singapore

Other Decks in Programming

Transcript

  1. Mutation Test Joseph Yao A Way to Learn How Good

    Your Unit Test is
  2. Who I am? n Agile Coach at Odd-e n Father,

    Husband... n Software Craftsman
  3. None
  4. Mutant

  5. Mutation Test Mutant causes any test failed? Killed Mutant Yes

    Survived Mutant No
  6. None
  7. Expectation of Automated Test Any Possible “Bad” Code Change can

    be Detected
  8. int foo (int x, int y)! {! int z =

    0;! if ((x>0) && (y>0)) {! z = x;! }! return z;! } int foo (int x, int y)! {! int z = 0;! if ((x>0) && (y>=0)) {! z = x;! }! return z;! } Unit Tests assertEquals(2, foo(2, 2)) assertEquals(0, foo(2, -1)) assertEquals(0, foo(-1, 2)) To assertEquals(2, foo(2, 2)) assertEquals(0, foo(2, 0)) assertEquals(0, foo(-1, 2))
  9. int foo (int x, int y)! {! int z =

    0;! if ((x>0) && (y>0)) {! z = x;! }! sideEffect(z);! return z;! } int foo (int x, int y)! {! int z = 0;! if ((x>0) && (y>0)) {! z = x;! }! sideEffect(z);! return z;! } n Either missing a test to prove the removed code is needed n Or the removed code is truly Redundant
  10. None
  11. Three Rules of TDD n You are not allowed to

    write any production code unless it is to make a failing unit test pass. n You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures. n You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
  12. None
  13. Survived Mutant

  14. Problematic Test

  15. Mutants n Conditionals Boundary n Negate Conditionals n Math n

    Increments n Invert Negatives n Inline Constant n Return Values n Void Method Calls n Non Void Method Calls n Constructor Calls More detail at http://pitest.org/quickstart/mutators/
  16. None
  17. NOT

  18. Equivalent Mutant >= >

  19. Mutation Test Tool

  20. None
  21. http://crestweb.cs.ucl.ac.uk/resources/ mutation_testing_repository/TR-09-06.pdf

  22. Q & A Email: joseph.yao.ruozhou@gmail.com Kata Video: http://tudou.com/home/yaoruozhou Github: https://github.com/JosephYao