Varol Cagdas Tok

Personal notes and articles.

Test Coverage and Mutation Testing

After writing a test suite, how do you assess its quality? How do you know when to stop testing? We need adequacy criteria, which are metrics for measuring test suite quality.

These criteria let us compare two test suites or decide if our current suite is sufficient.

The most common adequacy criteria are based on structural coverage. The principle is that a failure cannot be observed if the faulty code is never executed. While 100% coverage does not guarantee a bug-free program, low coverage indicates an inadequate test suite.

Here are the common structural coverage criteria, from weakest to strongest.

1. Statement Coverage

2. Branch Coverage

3. Modified Condition/Decision Coverage (MC/DC)

1. The value of B is the same in both tests.

2. The value of A is true in one test and false in the other.

3. The outcome of (A && B) is different for both tests.

4. Path Coverage

---

Mutation Testing

Mutation testing assesses test suite quality by measuring how many faults it can detect.

The process:

  1. Generate Mutants: The tool inserts small faults ("mutations") into your program. For example, it might change a + to a - (AOR operator) or a > to a >= (ROR operator).
  2. Execute Tests: The test suite runs against each mutant program.
  3. Assess:
  4. * If a test fails, it has killed the mutant, meaning the test suite found the fault.

    * If all tests pass, the mutant survived, indicating a gap in the test suite.

    The "Mutation Score Indicator" (MSI) is the percentage of mutants killed. This metric measures the fault-finding ability of your tests.