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 從公開儲存庫中收錄這些內容。

檢舉或申請下架

Mutation Testing · skills/mutation-testing 代理程式技能 | SourceWeft