New advertisers: 50% off your first month with code FIRSTMONTHSee slots
secondsky avatar

mutation-testing

Mutation testing skill that finds weak tests which pass despite deliberate code mutations.

version
3.12.0
GitHub stars
250
View on GitHub

What it does

  • Adds the mutation-testing skill covering Stryker for TypeScript and JavaScript and mutmut for Python
  • Supports Vitest and bun test projects, the latter through the @hughescr/stryker-bun-runner package
  • Shows how to run bunx stryker run and uv run mutmut run, then review results in HTML or via mutmut results
  • Designed for projects that already have high code coverage and need to confirm their assertions catch real faults

Validate test effectiveness with mutation testing using Stryker (TypeScript/JavaScript) and mutmut (Python). Find weak tests that pass despite code mutations. Use to improve test quality.

Add marketplace

/plugin marketplace add secondsky/claude-skills

Run it inside Claude Code once, then install the plugin below.

Install

/plugin install mutation-testing@claude-skills

Run it inside Claude Code after adding the marketplace.

Files

Discovered from source

Mutation Testing

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

Core Concept

  • Mutants: Small code changes introduced automatically
  • Killed: Test fails with mutation (good - test caught the bug)
  • Survived: Test passes with mutation (bad - weak test)
  • Score: Percentage of mutants killed (aim for 80%+)

TypeScript/JavaScript (Stryker)

Vitest Runner

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

# Using npm
npm install -D @stryker-mutator/core @stryker-mutator/vitest-runner
Configuration
// stryker.config.mjs
export default {
  packageManager: 'bun',
  reporters: ['html', 'clear-text', 'progress'],
  testRunner: 'vitest',
  coverageAnalysis: 'perTest',
  mutate: ['src/**/*.ts', '!src/**/*.test.ts'],
  thresholds: { high: 80, low: 60, break: 60 },
  incremental: true,
}

Bun Native Runner (bun test)

Use when projects use bun test directly (not Vitest).

Requirements
  • Bun >= 1.3.7 (needs TestReporter WebSocket events from Bun PR #25986)
  • @stryker-mutator/core ^9.6.1
Installation
bun add -D @hughescr/stryker-bun-runner @stryker-mutator/core
Configuration
// stryker.conf.mjs
export default {
  testRunner: 'bun',
  coverageAnalysis: 'perTest',
  mutate: ['src/**/*.ts', '!src/**/*.test.ts'],
  thresholds: { high: 80, low: 60, break: 60 },
  incremental: true,
  bun: {
    inspectorTimeout: 5000,  // WebSocket Inspector connection timeout (ms)
    // bunPath: '/path/to/bun',  // only if custom Bun install
    // timeout: 30000,           // test timeout (ms)
    // env: { DEBUG: 'true' },
    // bunArgs: ['--bail'],
  },
}
Key Behaviors
  • Sequential execution: Runs tests with --concurrency=1 for accurate per-test coverage. Slower than parallel but required for correct test-to-mutant correlation.
  • Concurrent test patching: Automatically patches describe.concurrent(), test.concurrent(), it.concurrent() to run sequentially during mutation testing — no code changes needed.
  • Inspector Protocol: Uses Bun's WebSocket Inspector API to discover tests and correlate coverage.

Running Stryker

# Run mutation testing
bunx stryker run

# Incremental mode (only changed files)
bunx stryker run --incremental

# Specific files
bunx stryker run --mutate "src/utils/**/*.ts"

# Open HTML report
open reports/mutation/html/index.html

Example: Weak Test

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

// ❌ WEAK: Test passes even if we mutate calculation
test('applies discount', () => {
  expect(calculateDiscount(100, 10)).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)
})

Python (mutmut)

Installation

uv add --dev mutmut

Running mutmut

# Run mutation testing
uv run mutmut run

# Show results
uv run mutmut results

# Show specific mutant
uv run mutmut show 1

# Generate HTML report
uv run mutmut html
open html/index.html

Common Mutation Types

// Arithmetic Operator
// Original: a + b → a - b, a * b, a / b

// Relational Operator
// Original: a > b → a >= b, a < b, a <= b

// Logical Operator
// Original: a && b → a || b

// Boolean Literal
// Original: true → false

Mutation Score Targets

ScoreQualityAction
90%+ExcellentMaintain quality
80-89%GoodSmall improvements
70-79%AcceptableFocus on weak areas
< 60%PoorMajor improvements needed

Improving Weak Tests

Pattern: Insufficient Assertions

// Before: Mutation survives
test('calculates sum', () => {
  expect(sum([1, 2, 3])).toBeGreaterThan(0) // Weak!
})

// After: Mutation killed
test('calculates sum correctly', () => {
  expect(sum([1, 2, 3])).toBe(6)
  expect(sum([0, 0, 0])).toBe(0)
  expect(sum([])).toBe(0)
})

Pattern: Boundary Conditions

// After: Tests boundaries
test('validates age boundaries', () => {
  expect(isValidAge(18)).toBe(true)   // Min valid
  expect(isValidAge(17)).toBe(false)  // Just below
  expect(isValidAge(100)).toBe(true)  // Max valid
  expect(isValidAge(101)).toBe(false) // Just above
})

Best Practices

  • Start with core business logic modules
  • Ensure 80%+ coverage before mutation testing
  • Run incrementally (only changed files)
  • Focus on important files first
  • Don't expect 100% mutation score (equivalent mutants exist)

Workflow

# 1. Ensure good coverage first
bun test --coverage
# Target: 80%+ coverage

# 2. Run mutation testing
bunx stryker run

# 3. Check report
open reports/mutation/html/index.html

# 4. Fix survived mutants
# 5. Re-run incrementally
bunx stryker run --incremental
# or: npx stryker run --incremental

See Also

  • vitest-testing - Unit testing framework
  • test-quality-analysis - Detecting test smells

Readme

Mutation Testing Skill

Validate test effectiveness with Stryker (TypeScript) and mutmut (Python).

Overview

Expert guidance for mutation testing - finding weak tests by introducing deliberate code mutations and checking if tests catch them.

Core Concept

  • Mutants: Small code changes introduced automatically
  • Killed: Test fails with mutation (good)
  • Survived: Test passes with mutation (weak test)
  • Score: Percentage killed (aim for 80%+)

When to Use

  • Validate test effectiveness
  • Find weak assertions
  • Improve test quality
  • After achieving high code coverage
  • Before major releases

Tools Supported

  • Stryker (TypeScript/JavaScript)
    • Vitest runner (@stryker-mutator/vitest-runner)
    • Bun native runner (@hughescr/stryker-bun-runner) — for bun test projects
  • mutmut (Python)

Quick Start

# TypeScript (Stryker)
bunx stryker run
open reports/mutation/html/index.html

# Python (mutmut)
uv run mutmut run
uv run mutmut results

Auto-Trigger Keywords

  • mutation testing
  • test effectiveness
  • weak tests
  • stryker
  • mutmut
  • test validation
  • code mutations
  • stryker-bun-runner
  • bun test mutation

Source

Adapted from laurigates/dotfiles

Details

Marketplace
secondsky/claude-skills
Source
plugins/mutation-testing
Category
Testing
Keywords
mutation-testing, mutation, testing, tests, unit-tests, quality
Listed since
Apr 7, 2026

More from secondsky/claude-skills

All 122

Similar to mutation-testing

More Testing & QA