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

Eeek, my tests are mutating

Eeek, my tests are mutating

Lander Vanderstraeten

November 07, 2017
Tweet

Other Decks in Programming

Transcript

  1. 4

  2. 6

  3. 8

  4. 10

  5. TESTS ARE A GOOD TOOL TO VERIFY YOUR CODE BUT

    HOW DO YOU VERIFY YOUR TESTS? 11
  6. CODE COVERAGE IS A START, BUT IT CAN GIVE A

    “GOOD” SCORE WITH USELESS TESTS 12
  7. Mutation testing is a technique to evaluate the quality of

    your tests by programmatically mutating and making a series of small modifications to your code so that the tests no longer pass. 16
  8. 17

  9. IF BUGS ARE CRIMES AND YOUR TESTS ARE THE POLICE

    MUTATIONS ARE FAKE CRIMES THAT LET YOU SEE THE POLICE IS DOING THEIR JOB 18
  10. TO ASSESS THE QUALITY OF A GIVEN TEST, MUTANTS ARE

    EXECUTED AGAINST THE INPUT TEST TO SEE IF THE SEEDED FAULTS CAN BE DETECTED. 19
  11. Each mutated version: Mutant Mutated program + failing tests: killed

    mutant Mutated program + passed tests: escaped mutant 21
  12. Test suites are measured by the percentage of mutants that

    they kill. New tests can be designed to kill additional mutants. 23
  13. EXAMPLE public function foobar(int $number): int { return $number +

    1; // original } public function foobar(int $number): int { return $number - 1; // mutated version } 26
  14. ANOTHER EXAMPLE public function foobar(?Bar $foo): string { if (null

    === $foo) { // original return 'foo'; } // ... } public function foobar(?Bar $foo): string { if (null !== $foo) { // mutated version return 'foo'; } // ... } 27
  15. 1. Always write unit tests 2. Code coverage gives a

    false positive feeling 3. Mutation testing also gives a false positive feeling 30