Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

mutation-testing

БесплатноЗапускает вложенные скриптыНе проверен

Mutation testing with Stryker (TS/JS) and mutmut (Python). Use when finding weak tests that pass on mutated code, or improving test quality through mutation…

laurigatesот laurigates★ 61 звезда на GitHub

Об этом скилле

Mutation Testing

Expert knowledge for mutation testing - validating that your tests actually catch bugs by introducing deliberate code mutations.

When to Use This Skill

Use this skill when... Use another skill instead when...
Validating test effectiveness Writing unit tests (use vitest-testing)
Finding weak/insufficient tests Analyzing test smells (use test-quality-analysis)
Setting up Stryker or mutmut Writing E2E tests (use playwright-testing)
Improving mutation score Generating test data (use property-based-testing)
Checking if tests catch real bugs Setting up code coverage only

Core Expertise

Mutation Testing Concept

  • Mutants: Small code changes (mutations) introduced automatically
  • Killed: Test fails with mutation (good - test caught the bug)
  • Survived: Test passes with mutation (bad - weak test)
  • Coverage: Tests execute mutated code but don't catch it
  • Score: Percentage of mutants killed (aim for 80%+)

What Mutation Testing Reveals

  • Tests that don't actually verify behavior
  • Missing assertions or edge cases
  • Overly permissive assertions
  • Dead code or unnecessary logic
  • Areas needing stronger tests

TypeScript/JavaScript (Stryker)

Installation

# Using Bun
bun add -d @stryker-mutator/core

# For Vitest
bun add -d @stryker-mutator/vitest-runner

# For Jest
bun add -d @stryker-mutator/jest-runner

Running Stryker

npx stryker run                                    # Run mutation testing
npx stryker run --incremental                      # Only changed files
npx stryker run --mutate "src/utils/**/*.ts"       # Specific files
npx stryker run --reporters html,clear-text        # HTML report
open reports/mutation/html/index.html              # View report

Understanding Results

Mutation score: 82.5%
- Killed: 66 (tests caught the mutation)
- Survived: 14 (tests passed despite mutation - weak tests!)
- No Coverage: 0 (mutated code not executed)
- Timeout: 0 (tests took too long)

Example: Weak vs Strong Test

// Source code
function calculateDiscount(price: number, percentage: number): number {
  return price - (price * percentage / 100)
}

// WEAK: Test passes even if we mutate the calculation
test('applies discount', () => {
  const result = calculateDiscount(100, 10)
  expect(result).toBeDefined() // Too weak!
})

// STRONG: Test catches mutation
test('applies discount correctly', () => {
  expect(calculateDiscount(100, 10)).toBe(90)
  expect(calculateDiscount(100, 20)).toBe(80)
  expect(calculateDiscount(50, 10)).toBe(45)
})

Static survivors under the Vitest runner are often false

A static mutant mutates code that runs at module load (constant maps, Zod schemas). Observed with @stryker-mutator/vitest-runner 10.0.0 on Vitest 4.1:

ignoreStatic: true Effect
Skips Static mutants that no test covers
Does not skip Static mutants some test covers — these run only against the 1-2 tests Stryker attributes coverage to, often unrelated files that imported the module first

So a static mutant can report Survived although the test that really asserts on that code would kill it. One Next.js app: 384 of 766 survivors were static: true with testsCompleted <= 5; excluding them moved the score from 68% to ~79%. A static survivor that ran against many tests is real (dropping .trim() from a Zod schema survived 195 tests, and stayed green across all 96 related tests when applied by hand). Count the survivors worth reading:

jq '[.files[].mutants[] | select(.status=="Survived" and ((.static|not) or .testsCompleted > 5))] | length' reports/mutation/mutation.json

The threshold 5 is a heuristic from that one codebase, not a Stryker-defined value. Tie-breaker for a suspicious static survivor: apply the mutation by hand and run the related tests — a red suite means the survivor was false.

Python (mutmut)

Installation

uv add --dev mutmut                    # Using uv
pip install mutmut                     # Using pip

Running mutmut

uv run mutmut run                                          # Run mutation testing
uv run mutmut run --paths-to-mutate=src/calculator.py      # Specific files
uv run mutmut results                                      # Show results
uv run mutmut summary                                      # Summary
uv run mutmut show 1                                       # Show specific mutant
uv run mutmut apply 1                                      # Apply mutant manually
uv run mutmut html                                         # HTML report

Understanding Results

Status: 45/50 mutants killed (90%)
- Killed: 45 (tests caught the mutation)
- Survived: 5 (tests passed despite mutation)

Hand-rolled harnesses report LESS than Stryker and mutmut do

Ev

Полный SKILL.md на GitHub

Установить mutation-testing в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Bash(npx stryker *)
Bash(uv run mutmut *)
Bash(uv run pytest *)
Bash(bun test *)
Bash(vitest *)
Bash(jq *)
Bash(grep *)
Read
Edit
Write
Grep
Glob
TodoWrite

Вложенные файлы

REFERENCE.mdreferences/hand-rolled-harness-failures.mdreferences/triaging-large-survivor-sets.mdworkflows/survivor-triage.workflow.js

FAQ

Что делает скилл mutation-testing?

Mutation testing with Stryker (TS/JS) and mutmut (Python). Use when finding weak tests that pass on mutated code, or improving test quality through mutation analysis.

Как установить скилл mutation-testing?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл mutation-testing запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить mutation-testing с