I built a mutation testing tool for Swift to check whether AI-written tests actually test anything

Over the past year, AI coding agents have been writing more and more of the tests in my projects. The number of tests went up, and so did coverage, but I couldn't keep up with reviewing whether those tests actually checked anything. Many of them exercised the code but made weak assertions, so they would pass whether the logic was correct or not.

Coverage alone doesn't answer that question. It tells you a line ran, not that any test would fail if that line was wrong. So I built xcmutate, a mutation testing tool for Swift and Xcode projects. It makes small changes to your code (for example > to >=), runs your tests against each change, and lists the changes that no test noticed.

brew install RyoHirota68/tap/xcmutate

# On a branch of an iOS app: mutate only the lines changed since main
xcrun simctl boot <SIMULATOR-UDID>
xcmutate run --since origin/main --project App.xcodeproj --scheme App \
  --destination 'id=<SIMULATOR-UDID>' --only-testing AppTests

--workspace App.xcworkspace and --package . work the same way.

GitHub: GitHub - RyoHirota68/xcmutate: Diff-driven mutation testing for Swift and Xcode projects · GitHub (MIT)

Why another tool

Muter is the established mutation testing tool for Swift, and I learned a lot from its design, issues and test data. I wanted something I could run on every pull request, which led to a different design:

  • Diff-based runs. --since <ref> mutates only the lines you changed, so a run covers a PR rather than whole files.
  • Results where you review. Surviving mutants are shown as warnings on their lines in Xcode and on GitHub pull requests. A GitHub Action is available for CI integration.
  • A CI gate for new gaps only. With --baseline-report, CI fails only on gaps that the main branch did not have, so an older codebase can adopt it without fixing everything first.
  • Not reached vs. not checked. Code that no test runs is reported as NotReached, separately from code that runs but whose change no test detects (Survived). They need different fixes.

A comparison page, including when Muter is the better choice, is here: xcmutate/docs/comparison.md at main · RyoHirota68/xcmutate · GitHub

How it works

All mutants are compiled into one build as switches (mutant schemata), so a run builds once. Mutation is done with swift-syntax on a copy of the repository; your files are not modified. Tests run through xcodebuild, with XCTest or Swift Testing, on macOS or an iOS simulator.

One challenge with mutation testing is that incorrect verdicts can easily go unnoticed: a mutant reported as Survived may never have been active, and a mutant reported as Killed may have failed a test for another reason, such as state left behind by the previous run. xcmutate gives a verdict only with evidence. A Survived needs a record that the mutant was switched on while the tests ran, and a Killed needs the same tests to have passed without mutants. Mutants it cannot judge are reported as such and not counted. Details: xcmutate/docs/verification.md at main · RyoHirota68/xcmutate · GitHub

Speed

After the one build, the time is mostly the cost of your tests. Time per mutant, not counting the build, on an M4 Pro Mac mini with 48 GB and Xcode 27.2:

Project Default --shared-process
Small package, macOS 2.0 s 0.3 s
Small iOS app, simulator 11 s 1.4 s
Large app, ~1,200 tests per mutant, test selection on 22-24 s

--shared-process runs many mutants in one test process instead of relaunching the tests for each. It is opt-in because it needs tests that pass twice in a row in the same process, which tests that leave state behind (in a singleton or on disk, for example) may not. When it can't be used, xcmutate says why and runs each mutant in its own process.

In my experience a typical PR diff produces a few dozen mutants, so a run takes minutes. Mutating the whole of a large app in one go is not practical. More measurements: xcmutate/docs/speed.md at main · RyoHirota68/xcmutate · GitHub

Coding agents

Since agents are writing many of the tests, the gaps can go back to them. xcmutate agent-guide prints a procedure an agent can follow to write the missing tests, and there is a JSON report for agents. The guide tells the agent to ask for approval before changing production code or accepting a mutant as equivalent.

Status

This is the first release (0.13.0), so options and report formats may still change before 1.0. UI tests are not supported, and tvOS and watchOS have not been tried; if you need those, Muter is worth checking out.

Any feedback is welcome, in whatever form: a reply here, an issue, or a pull request. Bug reports, "this didn't work on my project", feature ideas, or "I'd use it if it did X" all help.