Modern QA2026Template 4: Mutation-Aware Test Generation — tiles
Log inJoin
7 / 87 · 02 AI-Augmented Test Design · Prompt Templates for Test Generation← prev⊞ allnext →☰ Read as one page

2.5Template 4: Mutation-Aware Test Generation

This advanced template produces tests with higher bug-detection capability by incorporating mutation testing concepts directly into the prompt.

For the following {language} function, generate tests that would survive
mutation testing. For each test:

1. State the specific line of code or condition you are targeting
2. Explain what mutation (change) would break this test
3. Write the test with a tight assertion that catches the mutation

**Function under test:**
```{language}
{paste function code}

Requirements:

  • Each test must target a specific branch, condition, or calculation
  • Assertions must be precise enough that changing any operator (+, -, *, /), comparison (>, <, >=, <=, ==, !=), or constant would cause the test to fail
  • Include boundary values for every conditional
  • Do NOT write tests that only verify "no exception is thrown"

Example of a LOW mutation-score test (avoid this):

def test_create_user():
    response = client.post("/users", json={"name": "Alice"})
    assert response.status_code == 200
    # If the name is not saved, this test still passes. Low mutation score.

Example of a HIGH mutation-score test (aim for this):

def test_create_user():
    response = client.post("/users", json={"name": "Alice"})
    assert response.status_code == 200
    user = response.json()
    assert user["name"] == "Alice"   # Catches missing name persistence
    assert "id" in user              # Catches missing ID generation

### When to Use This Template

- When you are retrofitting tests onto legacy code and need high confidence
- When your team tracks mutation testing scores
- When you want to demonstrate testing depth in interviews
- When a critical function (payments, auth, data migration) needs airtight coverage