arabelatso/smart-mutation-operator-generator
Analyzes a repository and its test suite to generate customized mutation operators tailored to the project. Use this skill when setting up mutation testing, improving test quality, or generating project-specific mutants. Considers language constructs, business logic patterns, API calls, data types, and code complexity to produce effective mutation operators that maximize test sensitivity while avoiding trivial or equivalent mutations. Generates prioritized operator sets (high/medium/low value) with impact summaries. Triggers when users ask to generate mutation operators, customize mutation testing, analyze code for mutation opportunities, or create project-specific mutants.
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill smart-mutation-operator-generator
Generate customized mutation operators tailored to a specific codebase to maximize mutation testing effectiveness.
Run analysis script:
# Analyze entire repository
python scripts/generate_operators.py /path/to/repo
# Analyze single file
python scripts/generate_operators.py /path/to/file.py
# Save detailed report
python scripts/generate_operators.py /path/to/repo --output operators.json
Script analyzes:
Operator priorities:
Consider project characteristics:
Financial/calculation-heavy code:
API-heavy code:
Business logic code:
Data processing code:
Example custom operators:
API Timeout Mutation:
# Original
response = api.call(timeout=30)
# Mutant
response = api.call(timeout=1) # Test timeout handling
Retry Logic Mutation:
# Original
@retry(max_attempts=3)
def fetch_data():
pass
# Mutant
@retry(max_attempts=1) # Test with fewer retries
def fetch_data():
pass
Business Rule Mutation:
# Original
if age >= 18 and has_license:
allow_driving()
# Mutants
if age > 18 and has_license: # ROR
if age >= 18 or has_license: # LCR
if age >= 21 and has_license: # CRP (domain-specific)
Skip equivalent mutants:
# Equivalent (don't mutate)
x = a + 0 # → x = a - 0 (still equals a)
x = a * 1 # → x = a / 1 (still equals a)
# Non-equivalent (do mutate)
x = a + 1 # → x = a - 1 (different result)
x = a * 2 # → x = a / 2 (different result)
Skip trivial mutations:
# Trivial (low value)
message = "Hello" # → message = "" (obvious failure)
# Valuable (high value)
if count > 0: # → if count >= 0 (subtle boundary)
Document operator selection:
MUTATION TESTING PLAN
=====================
Project: MyApp
Language: Python
Files Analyzed: 45
SELECTED OPERATORS
------------------
High Priority (Apply to all code):
1. ROR - Relational Operator Replacement
- Target: Comparison operations in business logic
- Expected: 150 mutants
- Rationale: Critical for boundary condition testing
2. LCR - Logical Connector Replacement
- Target: Boolean expressions in validation
- Expected: 80 mutants
- Rationale: Tests logical condition coverage
3. CRP - Constant Replacement
- Target: Numeric thresholds and limits
- Expected: 120 mutants
- Rationale: Tests boundary values
Medium Priority (Apply selectively):
4. AOR - Arithmetic Operator Replacement
- Target: Calculation functions only
- Expected: 60 mutants
- Rationale: Financial calculations need thorough testing
Custom Operators:
5. RETRY - Retry Logic Mutation
- Target: @retry decorators
- Expected: 15 mutants
- Rationale: Test resilience mechanisms
ESTIMATED RESULTS
-----------------
Total Mutants: ~425
Mutation Score Target: >80%
Execution Time: ~25 minutes
Python (mutmut):
mutmut run --paths-to-mutate=src/
mutmut results
JavaScript (Stryker):
// stryker.conf.js
module.exports = {
mutator: {
excludedMutations: ['StringLiteral', 'UnaryOperator']
}
};
See standard_operators.md for complete list.
Most effective:
> → >=, <, ==and → or0 → 1, true → falseif x: → if not x:Mutation Score = (Killed Mutants / Total Mutants) × 100%
Targets:
Start small:
Focus on critical code:
Avoid over-mutation:
Review results:
# Analyze repository
python scripts/generate_operators.py /path/to/repo
# Save detailed report
python scripts/generate_operators.py /path/to/repo --output report.json
Output includes:
Take arabelatso/smart-mutation-operator-generator from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.