重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
mutation-testing by secondsky/claude-skills
npx skills add https://github.com/secondsky/claude-skills --skill mutation-testing变异测试的专业知识 - 通过引入故意的代码变异来验证您的测试是否真正捕获了错误。
# 使用 Bun
bun add -d @stryker-mutator/core @stryker-mutator/vitest-runner
# 使用 npm
npm install -D @stryker-mutator/core @stryker-mutator/vitest-runner
// 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 test)当项目直接使用 bun test(而非 Vitest)时使用。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
@stryker-mutator/core ^9.0.0bun add -D @hughescr/stryker-bun-runner @stryker-mutator/core
// 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 连接超时时间(毫秒)
// bunPath: '/path/to/bun', // 仅当使用自定义 Bun 安装时
// timeout: 30000, // 测试超时时间(毫秒)
// env: { DEBUG: 'true' },
// bunArgs: ['--bail'],
},
}
--concurrency=1 运行测试以获得准确的单测试覆盖率。比并行运行慢,但对于正确的测试到变异体关联是必需的。describe.concurrent()、test.concurrent()、it.concurrent() 以在变异测试期间顺序运行 — 无需更改代码。# 运行变异测试
bunx stryker run
# 增量模式(仅更改的文件)
bunx stryker run --incremental
# 特定文件
bunx stryker run --mutate "src/utils/**/*.ts"
# 打开 HTML 报告
open reports/mutation/html/index.html
// 源代码
function calculateDiscount(price: number, percentage: number): number {
return price - (price * percentage / 100)
}
// ❌ 薄弱:即使我们改变计算,测试也能通过
test('applies discount', () => {
expect(calculateDiscount(100, 10)).toBeDefined() // 太弱了!
})
// ✅ 强大:测试捕获了变异
test('applies discount correctly', () => {
expect(calculateDiscount(100, 10)).toBe(90)
expect(calculateDiscount(100, 20)).toBe(80)
expect(calculateDiscount(50, 10)).toBe(45)
})
uv add --dev mutmut
# 运行变异测试
uv run mutmut run
# 显示结果
uv run mutmut results
# 显示特定变异体
uv run mutmut show 1
# 生成 HTML 报告
uv run mutmut html
open html/index.html
// 算术运算符
// 原始: a + b → a - b, a * b, a / b
// 关系运算符
// 原始: a > b → a >= b, a < b, a <= b
// 逻辑运算符
// 原始: a && b → a || b
// 布尔字面量
// 原始: true → false
| 得分 | 质量 | 行动 |
|---|---|---|
| 90%+ | 优秀 | 保持质量 |
| 80-89% | 良好 | 小幅改进 |
| 70-79% | 可接受 | 关注薄弱区域 |
| < 60% | 差 | 需要重大改进 |
// 之前:变异体存活
test('calculates sum', () => {
expect(sum([1, 2, 3])).toBeGreaterThan(0) // 薄弱!
})
// 之后:变异体被杀死
test('calculates sum correctly', () => {
expect(sum([1, 2, 3])).toBe(6)
expect(sum([0, 0, 0])).toBe(0)
expect(sum([])).toBe(0)
})
// 之后:测试边界
test('validates age boundaries', () => {
expect(isValidAge(18)).toBe(true) // 最小有效值
expect(isValidAge(17)).toBe(false) // 刚好低于
expect(isValidAge(100)).toBe(true) // 最大有效值
expect(isValidAge(101)).toBe(false) // 刚好高于
})
# 1. 首先确保良好的覆盖率
bun test --coverage
# 目标:80%+ 覆盖率
# 2. 运行变异测试
bunx stryker run
# 3. 检查报告
open reports/mutation/html/index.html
# 4. 修复存活的变异体
# 5. 增量重新运行
bunx stryker run --incremental
# 或: npx stryker run --incremental
vitest-testing - 单元测试框架test-quality-analysis - 检测测试异味每周安装量
60
仓库
GitHub 星标数
91
首次出现
2026 年 1 月 25 日
安全审计
安装于
claude-code53
gemini-cli48
cursor48
codex47
opencode46
github-copilot44
Expert knowledge for mutation testing - validating that your tests actually catch bugs by introducing deliberate code mutations.
# Using Bun
bun add -d @stryker-mutator/core @stryker-mutator/vitest-runner
# Using npm
npm install -D @stryker-mutator/core @stryker-mutator/vitest-runner
// 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 test)Use when projects use bun test directly (not Vitest).
@stryker-mutator/core ^9.0.0bun add -D @hughescr/stryker-bun-runner @stryker-mutator/core
// 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'],
},
}
--concurrency=1 for accurate per-test coverage. Slower than parallel but required for correct test-to-mutant correlation.describe.concurrent(), test.concurrent(), it.concurrent() to run sequentially during mutation testing — no code changes needed.# 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
// 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)
})
uv add --dev 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
// 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
| Score | Quality | Action |
|---|---|---|
| 90%+ | Excellent | Maintain quality |
| 80-89% | Good | Small improvements |
| 70-79% | Acceptable | Focus on weak areas |
| < 60% | Poor | Major improvements needed |
// 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)
})
// 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
})
# 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
vitest-testing - Unit testing frameworktest-quality-analysis - Detecting test smellsWeekly Installs
60
Repository
GitHub Stars
91
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code53
gemini-cli48
cursor48
codex47
opencode46
github-copilot44
代码审查最佳实践指南:完整流程、安全与性能审查清单
12,400 周安装
AGENTS.md 编写指南 - 为 AI 智能体创建高效文档的完整规范与最佳实践
1,000 周安装
Microsoft Agent Framework 开发指南:统一Semantic Kernel与AutoGen的AI智能体框架
980 周安装
Go性能优化指南:从分析到实践,提升Golang应用性能
968 周安装
WordPress性能优化指南:后端诊断、数据库查询优化与TTFB提升方案
945 周安装
OpenClaw主机安全加固指南:评估风险、制定计划、分步执行
954 周安装
session-logs 技能:搜索和管理 OpenClaw 会话日志的完整指南
954 周安装