/swift-mutation-testing:swift-mutation-testingfrom Swift Mutation Testing
Runs mutation testing on Swift packages or Xcode projects using swift-mutation-testing, analyzes the report, and generates tests to kill surviving mutants. Useful for evaluating test suite quality beyond code coverage.
Ships in Swift Mutation Testing. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
swift-mutation-testing changes the code under test in small ways — < to <=, true to false, a call removed — and runs the test suite once per change. Each change is a mutant. A mutant the tests catch is killed. A mutant no test notices survived: the code can be wrong in that exact way and the suite still passes. Coverage says a line ran; a survivor says nothing checked what it did.
The project is never modified. Every build and test run happens in a copy under $TMPDIR/swift-mutation-testing/. Those copies are kept between runs (warm-<key>-<n>), each with a full build of the project, so the next run builds incrementally; --no-warm-sandbox removes them and builds from scratch.
Reference, when a detail here is not enough: Usage and Mutation results.
swift-mutation-testing --version. If it is missing, ask the user before installing it with brew tap ericodx/homebrew-tools && brew install swift-mutation-testing. It needs macOS 15+ and Swift 6.2+.--timeout, it stops with exit code 1 and names the failing tests (--keep-logs <dir> keeps the suite's output as baseline.log). Fix those first.If the project has no .swift-mutation-testing.yml, generate one:
swift-mutation-testing init <project-path>
init detects the project type, the scheme and destination (Xcode), the workspace or project to build, the test target and the testing library. Read the generated file and check the scheme, the destination and test-target before running. Skip init when the file already exists: it holds the user's settings.
Xcode workspaces. An app with CocoaPods, several projects or local packages is a workspace, and it is built as one. The tool takes the single .xcworkspace (else the single .xcodeproj) at the project root. When there are two, or when the only ones sit in a subdirectory, it refuses to guess: the run stops naming the candidates, and init writes them commented out. Then ask the user which one the app is built from, and pass it with --workspace App.xcworkspace or --project App.xcodeproj (relative to the project root), or set the workspace / project key. Keep Pods/ out of scope with --exclude /Pods/ when it sits under the sources path. A workspace that references projects outside the project root cannot be run from that root; run from a directory that contains them all.
Extra xcodebuild arguments. When the project only builds with arguments the tool does not pass — -allowProvisioningUpdates, an -xcconfig, a build setting — add each with --xcodebuild-arg (repeatable), or list them under the xcodebuild-args key. They are appended to every xcodebuild call. The arguments the tool sets itself (-scheme, -destination, -workspace, -project, -derivedDataPath, the actions and a few test flags) are refused; use the tool's own options for those.
Always write the JSON report, because the text summary is for people and the JSON is what you read:
swift-mutation-testing <project-path> --output mutation-report.json
A Swift package needs no scheme or destination. An Xcode project needs both, in the file or as --scheme and --destination "platform=macOS" (or a simulator destination).
Narrowing the scope:
| Goal | How |
|---|---|
| One module, folder or file | --sources-path Sources/MyModule, or a single .swift file to re-check it after adding a test |
| Skip generated or vendored code | --exclude "**/Generated/**" (a glob, relative to the project root) or --exclude /Generated/ (a fragment of the path); repeatable |
| A few operators | --operator RelationalOperatorReplacement --operator NegateConditional |
| Every operator, including the experimental ones | --operator-tier experimental; the default tier is default — LogicalOperatorReplacement, NegateConditional, SwapTernary — see Docs/OPERATORS.md |
| One test target | --target MyPackageTests |
Test files (Tests/, Mocks/, Stubs/, Fakes/, TestHelpers/, TestSupport/, *Tests.swift, *Mock.swift, *Spec.swift), build output (.build/, DerivedData/), package manifests (Package.swift, Package@swift-*.swift) and Snippets/ are never mutated, and neither are the branches of an #if the macOS build leaves out (#if os(Windows), #if canImport(Glibc)).
A second run on unchanged code is fast: verdicts are cached in .swift-mutation-testing-cache/, keyed by file contents. Editing a source file re-tests that file's mutants; editing a test file re-tests every mutant except the unviable ones and the ones killed by a test in another file. The cache also holds the coverage map — which tests reach each function — so a mutant runs only the tests that reach its code; --no-cache drops the map too and makes every mutant run its whole suite. Use --no-cache only to rule out the cache when a result looks wrong.
The text summary ends with:
Overall mutation score: 85.3%
Detected: 122 (killed 122, timeout 0) / Undetected: 21 (survived 21, no coverage 0)
Killed: 122 / Survived: 21 / Timeouts: 0 / Unviable: 4 / NoCoverage: 0
detected = killed + timeouts
undetected = survived + noCoverage
score = detected / (detected + undetected) × 100
Each mutant in the JSON report (files["/Sources/Foo.swift"].mutants[]) carries mutatorName, originalText, replacement, location.start.line and .column (both 1-based), status, killedBy when a test killed it, and a fingerprint that identifies the mutant across runs. Its status is one of:
status | Meaning | Action |
|---|---|---|
Killed | A test failed with the mutant active. statusReason: "crash" means the process crashed instead | None |
Timeout | The suite never finished, even when rerun with fewer workers. Counts as detected | None, unless there are many: check --timeout |
Survived | The suite passed with the mutant active | Write a test (step 5) |
NoCoverage | No test ran the mutated code — measured, not guessed: either no test reached its function when the unmutated suite ran (the mutant is then not run at all), or the suite passed and the mutant's code never recorded that it executed | Write a test that reaches the code first |
CompileError | The mutant did not compile | None. It is a property of the operator, not of the tests, and it is outside the score |
A 100% score means every mutant that compiled was detected. It does not mean the code is right. When no mutant could be tested — every one CompileError — there is no score: the summary prints n/a, and --min-score and --max-score-drop fail.
Two lines can follow the summary. Integrity warnings (N) lists mutants that were killed or timed out without their code running: the test that failed did not fail because of the mutation, so treat those as flaky or broken tests, not as mutants to fix. A kill without activation was already run a second time, alone, and failed again, so it is not a one-off flake; in the JSON they carry statusReason: "killed without activation" (or crash …, timed out …). Activation not measured: N mutants means those mutants could not be instrumented, so for them a passing suite reads survived even if the code never ran.
The run stops with exit code 1, before reporting anything, when the project does not build without mutations (The unmutated project does not build, after the build's output), when a mutant did not reach the build (… not applied to the sandbox) or when mutants were killed but no mutant's code was ever seen running. Each means the verdicts could not be trusted; the message says which. For the first, make the project build from the command line before running again; when it needs extra xcodebuild arguments to build, pass them with --xcodebuild-arg. Report the error to the user rather than working around it.
Work through the undetected mutants in this order:
NoCoverage before Survived. A whole path is untested, which is worse than a weak assertion.RelationalOperatorReplacement surviving on >= and > at the same line means the boundary value is never tested.What each operator's survivor usually means:
| Operator | A survivor usually means |
|---|---|
RelationalOperatorReplacement | The boundary value (x == limit) is not tested |
BooleanLiteralReplacement | A flag's effect is not asserted |
LogicalOperatorReplacement | Only cases where both sides agree are tested |
ArithmeticOperatorReplacement | The computed value is not asserted exactly |
NegateConditional | Only one side of the branch is tested |
SwapTernary | Both results of the ternary are never compared |
RemoveSideEffects | The call's effect (state change, callback, write) is not verified |
location.start.line. Apply originalText → replacement in your head and say what behavior changes.--sources-path), with --output. Confirm the mutant now reports Killed and killedBy names your test.Never make a survivor go away by changing production code to avoid the mutation, by weakening an operator, or by excluding the file. The survivor is information about the tests, and the fix belongs in the tests.
When a test fails in a way you do not understand, rerun with --keep-logs <dir>: each mutant's full test output lands in <dir>/<mutant-id>.log, with an activated: line in the header saying whether the mutated code ran during that test run.
To look at one verdict closely, swift-mutation-testing reproduce <id-or-fingerprint> runs that mutant alone with the whole suite and no stop at the first failure, keeps its sandbox, and prints the sandbox path, the line before and after the mutation, the complete test output and the verdict with its reason. Read the output before writing a test.
Some survivors are equivalent: the mutation does not change observable behavior (for example a > b ? a : b → a >= b ? a : b: when a == b both return the same value). No test can kill them. Tell the user which ones you believe are equivalent and why, rather than writing a meaningless test.
To keep code out of the run, use --exclude (or exclude: in the config file) for generated and vendored files. For one declaration or one line, write the comment // swift-mutation-testing:disable above the declaration, or // swift-mutation-testing:disable-next-line above the line, with the reason after it (// swift-mutation-testing:disable — equivalent: reserveCapacity is a hint). Suppress only with the user's agreement and never to make a survivor disappear. Do not use the old @SwiftMutationTestingDisabled attribute: Swift rejects it unless the project declares it.
--sarif-output and --markdown-output, uploads the SARIF with github/codeql-action/upload-sarif so each survivor becomes an annotation on its line in the pull request, writes the Markdown to the job summary, and only then fails the job with the tool's exit code. Uploading SARIF needs permissions: security-events: write. Adapt that workflow rather than writing one from scratch..swift-mutation-testing.yml so CI runs with no extra flags: swift-mutation-testing --quiet --output mutation-report.json. --sarif-output writes a SARIF 2.1.0 report and --markdown-output a Markdown summary for CI systems that render it..swift-mutation-testing-cache/ between runs (actions/cache), keyed on the Swift sources and tests. The cache also holds a journal of verdicts, so a run that was cut short continues on the next run.swift-mutation-testing plan --output plan.json writes the mutants without building; run --plan plan.json --shard i/n runs one slice on each machine; merge result-*.json --plan plan.json --output … joins the slices into one report and runs the gate over it. The usage guide has a GitHub Actions matrix for this under "Plans". A shard must check out the commit the plan was made from, or it refuses to run.0 the run completed (and the quality gate passed, if set); 1 an error (bad arguments, a build that failed, a suite that fails without mutations, an unusable baseline); 2 the quality gate failed. On 2 the reports were still written.--min-score 80 (or min-score: 80 in the config file): fail below a score.swift-mutation-testing --write-baseline .swift-mutation-testing-baseline.json # commit this file
swift-mutation-testing --baseline .swift-mutation-testing-baseline.json --max-new-survivors 0
--max-score-drop 2 with --baseline: fail when the score falls more than 2 points below the baseline's.--max-integrity-warnings 0: fail when any mutant was killed or timed out without its code running, so a flaky suite cannot inflate the score. Needs no baseline.--sonar-output writes survivors as SonarQube external issues; --html-output writes a report for people.--operator, --sources-path or --exclude scores a different set of mutants than a full run.--sources-path or --exclude differ from the baseline's stops with exit code 1 and lists the differences. Run with the baseline's scope, or write a new baseline on purpose.platform=macOS is faster and needs no simulator.Failed to clone simulator <udid>. and the data size; suggest xcrun simctl erase <udid> or a device created for mutation testing. The clones' first boot keeps the machine busy for a few minutes, and the first mutants take longer while it lasts.$TMPDIR/swift-mutation-testing/ holds a full build of the project. When disk space is short, run with --no-warm-sandbox, or delete that directory when no run is active.--timeout in the parallel pass (--timeout is 30 s for packages, 120 s for Xcode by default), then is rerun once with fewer workers, under --timeout, before it is reported.mutation-report.json and .swift-mutation-testing-cache/ to .gitignore.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub ericodx/swift-mutation-testing --plugin swift-mutation-testingOther plugins' skills for the same job