Home Knowledge Base Mutation testing

Mutation testing is a software testing technique that assesses test suite quality by introducing small, deliberate changes (mutations) to the code and checking whether the tests detect these changes — if tests fail when the code is mutated, the tests are effective; if tests still pass, the tests are inadequate.

How Mutation Testing Works

1. Original Program: Start with the correct, working code.

2. Generate Mutants: Create modified versions of the code by applying mutation operators.

3. Run Tests: Execute the test suite against each mutant.

4. Classify Mutants:

5. Mutation Score: killed / (total - equivalent) — percentage of non-equivalent mutants killed.

Mutation Operators

Example: Mutation Testing

# Original code:
def is_positive(x):
    return x > 0

# Test:
assert is_positive(5) == True

# Mutant 1: Change > to >=
def is_positive(x):
    return x >= 0  # Mutant

# Run test: assert is_positive(5) == True → Still passes!
# Mutant survived — test is inadequate (doesn't test boundary case x=0)

# Better test suite:
assert is_positive(5) == True
assert is_positive(0) == False  # This would kill the mutant
assert is_positive(-3) == False

Why Mutation Testing?

Mutation Testing Process

1. Baseline: Run tests on original code — all should pass. 2. Generate Mutants: Apply mutation operators to create mutant programs. 3. Execute Tests: Run test suite on each mutant. 4. Analyze Results: Identify killed vs. survived mutants. 5. Improve Tests: Write new tests to kill surviving mutants. 6. Iterate: Repeat until mutation score is satisfactory (typically 80%+).

Challenges

Optimization Techniques

Mutation Testing Tools

Mutation Score Interpretation

Applications

LLMs and Mutation Testing

Benefits

Mutation testing is the gold standard for evaluating test suite quality — it directly measures the ability of tests to detect faults, providing actionable feedback for improving test effectiveness.

mutation testingsoftware testing

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.