Swift Mutation Testing

Measure and improve test effectiveness in Swift codebases using mutation testing.
swift-mutation-testing is a CLI for mutation testing of Swift projects — both Xcode and Swift Package Manager. It modifies your source code in small, targeted ways — mutations — and runs your test suite against each one. A mutation that goes undetected reveals missing tests or weak assertions. The result is a mutation score that reflects how effectively your tests catch real bugs.
Why
Traditional test coverage does not guarantee that tests catch real bugs.
Mutation testing introduces controlled changes to your code to verify that your tests fail when behavior changes. Surviving mutations indicate gaps in test effectiveness.
Features
- Mutation testing for Xcode projects and workspaces and for SPM packages — every project and module of a workspace in one build
- Supports both XCTest and Swift Testing frameworks
- 7 mutation operators (relational, boolean, logical, arithmetic, negate conditional, swap ternary, remove side effects), in tiers measured on real packages —
--operator-tier picks how deep a run goes, see Operators
- Schematization — builds once, tests all mutants via runtime switch; a coverage map from the unmutated run gives each mutant only the tests that reach its code, and reports a mutant no test reaches as no coverage without running it
- Activation verification — every verdict records whether the mutated code actually ran; a passing suite that never reached it is reported as no coverage, and a mutant missing from the build stops the run
- Parallel test execution with configurable concurrency
- Built sandboxes kept between runs in
$TMPDIR/swift-mutation-testing, so the next run builds incrementally (--no-warm-sandbox builds from scratch)
--timing shows how a run's time splits between its phases
- SHA256-based result caching across runs, with a journal that lets an interrupted run continue where it stopped
- Plans:
plan writes what a run will do, run --plan --shard i/n executes a slice of it on any machine, merge joins the slices into one report, reproduce reruns one mutant with its sandbox kept
- Multiple report formats: text, JSON (Stryker-compatible), HTML, SonarQube, SARIF (GitHub code scanning), Markdown
- Pull request annotations through GitHub code scanning, and a job summary, from the SARIF and Markdown reports
- Simulator pool for simulator destinations: one clone of the destination's simulator per worker, cloned and booted while the schema builds
- Mutation suppression by comment —
// swift-mutation-testing:disable on a declaration, // swift-mutation-testing:disable-next-line on a line
- Quality gate for CI: minimum score, maximum drop, no new survivors against a committed baseline, and a limit on integrity warnings
- Configurable via YAML or CLI flags
- CI/CD ready with caching support
Install
brew tap ericodx/homebrew-tools
brew install swift-mutation-testing
Other installation methods — pre-built binary, build from source — are covered in the Installation Guide.
Quick start
# Generate a config file (auto-detects project type, workspace or project, scheme, destination, test target and testing framework)
swift-mutation-testing init
# Run mutation testing
swift-mutation-testing
# Run on an SPM package (no scheme or destination needed)
swift-mutation-testing /path/to/my-package
Example output: