4.5.16 · D3Software Engineering

Worked examples — Mutation testing

2,611 words12 min readBack to topic

This page is the hands-on drill for Mutation testing. The parent note built the vocabulary (mutant, killed, survived, equivalent) and the score formula. Here we exhaust every kind of situation a mutation-testing question can throw at you and work each one from zero.


The scenario matrix

Before any example, here is the full space of cases. Each worked example is tagged with the cell it fills.

Cell Case class The tricky part
C1 Killed mutant (obvious) Mutant changes output on an existing test input
C2 Survived mutant (missing boundary) The differing input value is never tested
C3 Boundary fix Add the exact value where operators diverge
C4 Equivalent mutant Syntactically changed, behaviour identical → uncountable
C5 Score with equivalents Must remove from the denominator
C6 Degenerate suite (no asserts) 100% coverage, score
C7 Zero / limiting inputs Score when , , or (division by zero)
C8 Real-world word problem Translate a business rule into kill/survive reasoning
C9 Exam twist (two operators, one line) Pick which mutant survives and why

C1 — The obvious kill

Cell filled: C1.


C2 & C3 — Survivor, then the boundary fix

Cells filled: C2, C3.


C4 — An equivalent mutant (can never die)

Cell filled: C4.


C5 — Score computation with equivalents

Figure — Mutation testing

Cell filled: C5.


C6 — Degenerate suite: 100% coverage, score 0

Cell filled: C6.


C7 — Limiting values of the score

Cell filled: C7 (all three limits).


C8 — Real-world word problem

Cell filled: C8.


C9 — Exam twist: one line, two possible mutants

Cell filled: C9.


Recall Which cell was each example?

C1 obvious kill ::: sign with <> C2 + C3 survivor + boundary fix ::: can_vote >=>, fixed by testing age 18 C4 equivalent ::: range(x)range(0,x) C5 score with equivalents ::: C6 no-assert suite ::: 100% coverage, 0% mutation score C7 limits ::: , , and undefined () C8 word problem ::: free-shipping at exactly ₹500 C9 exam twist ::: andor dies, <=< survives


Connections

  • ← Back to the parent topic
  • Boundary value analysis — cells C2, C3, C8, C9 are all boundary survivors.
  • Unit testing — every "add an assert" fix strengthens a unit test.
  • Code coverage — cell C6 is the coverage-vs-mutation gap made concrete.
  • Continuous integration — where the C8 nightly mutation run lives.
  • Test-driven development — writing the boundary test first pre-empts C2-style survivors.
  • Fault injection — the broader family these deliberate mutants belong to.