Mutation Testing

aj-geddes/useful-ai-prompts/skills/mutation-testing

作者 aj-geddes3f5182cfd739无许可证355 个星标收录于 2026年10月8日更新于 2026年10月8日仓库7个月前更新

Evaluate test suite quality by introducing code mutations and verifying tests catch them. Use for mutation testing, test quality, mutant detection, Stryker, PITest, and test effectiveness analysis.

AI 生成的概览

通过引入代码变异并检查测试能否捕获,来评估测试套件的质量。

功能
该技能指导变异测试:向源代码引入小的改动(变异),验证测试套件是否按预期失败。内容涵盖 JavaScript/TypeScript 的 Stryker、Java 的 PITest 和 Python 的 mutmut 的配置与使用,以及如何解读变异测试报告。它还附带一个测试脚手架脚本和一个 JavaScript 测试模板。
适用场景
适用于评估测试套件的有效性、发现未被测试的代码路径、改进测试质量指标,或验证关键业务逻辑是否得到充分测试。也适合在行覆盖率之外衡量真实覆盖率,并识别薄弱或冗余的测试。
运行要求
需要一个 JavaScript/TypeScript、Java 或 Python 项目及其测试运行器,并安装相应的变异测试工具(Stryker、PITest 或 mutmut)。Stryker 快速上手需要 Node.js/npm。该技能附带可执行脚本和一个模板。

Mutation Testing

Table of Contents

Overview

Mutation testing assesses test suite quality by introducing small changes (mutations) to source code and verifying that tests fail. If tests don't catch a mutation, it indicates gaps in test coverage or test quality. This technique helps identify weak or ineffective tests.

When to Use

  • Evaluating test suite effectiveness
  • Finding untested code paths
  • Improving test quality metrics
  • Validating critical business logic is well-tested
  • Identifying redundant or weak tests
  • Measuring real test coverage beyond line coverage
  • Ensuring tests actually verify behavior

Quick Start

Minimal working example:

bash
# Install Strykernpm install --save-dev @stryker-mutator/core @stryker-mutator/jest-runner
# Initialize configurationnpx stryker init
# Run mutation testingnpx stryker run

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Stryker for JavaScript/TypeScript [blocked]Stryker for JavaScript/TypeScript
PITest for Java [blocked]PITest for Java
mutmut for Python [blocked]mutmut for Python
Mutation Testing Reports [blocked]Mutation Testing Reports

Best Practices

✅ DO

  • Target critical business logic for mutation testing
  • Aim for 80%+ mutation score on important code
  • Review survived mutants to improve tests
  • Mark equivalent mutants to exclude them
  • Use mutation testing in CI for critical modules
  • Test boundary conditions thoroughly
  • Verify actual behavior, not just code execution

❌ DON'T

  • Expect 100% mutation score everywhere
  • Run mutation testing on all code (too slow)
  • Ignore equivalent mutants
  • Test getters/setters with mutations
  • Run mutations on generated code
  • Skip mutation testing on complex logic
  • Focus only on line coverage

来源与署名

来源:aj-geddes/useful-ai-prompts位于skills/mutation-testing提交3f5182c

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架