Mutation testing in five minutes

What a mutant is

A mutant is a deliberately broken copy of the code. Take the reference implementation and change one detail: <= becomes <, and becomes or, return [] replaces an honest filter.

The idea

Line coverage answers a different question: "was this line executed?" Mutation testing asks: "would the tests notice if the code broke?"

def search(items, limit):
    return [i for i in items if i["price"] <= limit]

The mutant changes <= to <. If no test fails, the boundary price == limit is not covered by an assertion.

The rule

A good test fails when the code breaks. A bad test passes no matter what. assert True passes on the reference and on every mutant, so mutation testing exposes it immediately.

How to use it

  1. Write tests against the reference implementation.
  2. Run them against every mutant.
  3. A surviving mutant is a hole in the suite. Add a check that kills it.

In QA Lab every task works this way: a solution counts only when the tests pass on the reference and kill every mutant.