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

Agile Singapore

November 08, 2013
Tweet

More Decks by Agile Singapore

Other Decks in Programming

Transcript

  1. Who I am? n Agile Coach at Odd-e n Father,

    Husband... n Software Craftsman
  2. 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))
  3. 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
  4. 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.
  5. 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/
  6. NOT