Muter
🔎 Automated mutation testing for Swift 🕳️
Install / Use
/learn @muter-mutation-testing/MuterREADME
Automated mutation testing for Swift inspired by Stryker, PITest, and Mull
Muter can be run within Xcode
Use this mode to rapidly diagnose areas where you can begin improving your test code
<picture> <source media="(prefers-color-scheme: dark)" srcset="./Docs/Images/muter-in-xcode-dark.png"> <img alt="Muter running inside Xcode" src="./Docs/Images/muter-in-xcode-light.png"> </picture>Muter can be run from the command line
Use this mode to get detailed information about the health and quality of your entire test suite
<!-- asciinema rec muter-cli-output.cast agg --theme solarized-light --font-size 40 --cols 100 --speed 1 muter-cli-output.cast muter-light.gif agg --theme solarized-dark --font-size 40 --cols 100 --speed 1 muter-cli-output.cast muter-dark.gif ffmpeg -i file.gif -pix_fmt yuv420p output.mp4 --><video src="https://github.com/muter-mutation-testing/muter/assets/7672056/d022fa00-46bd-4b8a-b0d4-53d72c7c73b5"></video>
Muter can be run in your CI
Use this script to easily mutation test your projects incrementally, enabling you to have per-commit updates on how code changes impact the quality of your test suite. Seamlessly connect the output of this CI step into your dashboard or communication channel of choice, or use it as a starting point for thinking about how you want to incrementally test your code.
muter --files-to-mutate $(echo \"$(git diff --name-only HEAD HEAD~1 | tr '\n' ',')\")
Table of Contents
Introduction
Getting Started
What Is Muter?
Muter is a mutation testing utility that is used to help you determine the quality of your test suite.
With Muter, you can make sure your test suite is meeting all your requirements, fails meaningfully and clearly, and remains stable in the face of unexpected or accidental code changes.
If you're interested in checking out more about mutation testing, you can check out this link.
Why Should I Use This?
Muter can strengthen your test suite and shine a light on weaknesses that you were unaware existed. It does this by generating a mutation score (expanded on below), which will show you both the areas you may want to improve in your test suite, as well as the areas that are performing well.
Specifically, a mutation score can help you:
- Find gaps in fault coverage from your test suite by identifying missing groups of tests, assertions, or test cases from your test suite
- Determine if you are writing meaningful and effective assertions that withstand different code than what the test was originally written against
- Assess how many tests fail as a result of one code change
How Does It Work?
Muter will introduce changes to your source code based on the logic contained in your app. The changes introduced by Muter are called mutants which it generates using mutation operators.
You can view the list of available mutation operators here.
NOTE: Muter does all of its work on a complete copy of your codebase, so it's not possible for it to accidentally leave anything behind.
Mutation Score
A mutation score is provided at the end of every run of Muter. The score is the ratio of the number of mutants your test suite killed versus the total number of mutants introduced.
mutation score = number of mutants killed / total number of mutants
For example, if your test suite killed 50 mutants of the 75 introduced by Muter, your score would be 67%. A well-engineered test suite should strive to be as close to 100% as possible.
Muter not only provides a mutation score for your entire test suite, but it also generates individual scores for the files it has mutated.
If you're curious about how a mutation score is different than test code coverage, then check out this document.
Installation
Muter is available through Homebrew. Run the following command to install Muter:
brew install muter-mutation-testing/formulae/muter
Building From Source
You can build Muter from source, and get the latest set of features/improvements, by running the following:
git clone https://github.com/muter-mutation-testing/muter.git
cd muter
make install prefix=$(brew --prefix)
If you've already installed Muter via homebrew, this will install over it. If you've done this, and want to go back to the latest version you've downloaded through homebrew, run the following:
make uninstall prefix=$(brew --prefix)
brew unlink muter && brew link muter
Development
To run Muter directly from Xcode:
- Open Muter's scheme editor (Product > Scheme > Edit Scheme)
- Select the
Runscheme - In the
Optionstab, enableUse custom working directory - In the
Arguments tab, add any desired command line arguments underArguments Passed on Launch
You can now run Muter directly from Xcode using the standard run command (⌘R).
Note: To pass arguments on launch, you can use Xcode's Scheme Editor and add them.
Setup
Muter's Configuration
To get started using Muter, run muter init in the root of your project directory. Muter will take its best guess at a configuration that will work for your project. Muter supports generating configurations for the following build systems:
- Xcode Projects & Workspace
- Swift Package Manager
It saves its configuration into a file named muter.conf.yml, which you should keep in the root directory of your project. You should version control your configuration file as well.
After running muter init, you should look at the generated configuration and ensure that it will run your project. We recommend trying the settings it generates in your terminal, and verifying those commands run your tests.
Should you need to modify any of the options, you can use the list below to understand what each configuration option does.
Configuration Options
-
executable- the absolute path to the program which can run your test suite (likexcodebuild,swift,fastlane,make, etc.) -
arguments- any command line arguments the executable needs to run your test suite -
exclude- a list of paths, file extensions, or names you want Muter to ignore. By default, Muter ignores all non-Swift files, and any paths containing the following phrases:-
/.build/ -
/.framework/ -
/.swiftdep/ -
/.swiftmodule/ -
/Build/ -
/Carthage/ -
/muter_tmp/ -
/Pods/ -
/Spec/ -
/Tests/ -
Tests.swift -
/Package.swiftThe
excludeoption is optional.NOTE: Muter uses a substring match to determine if a file should be excluded from mutation testing. You should not use glob expressions (like
**/*Model.swift) or regex.
-
-
excludeCalls- a list of function names you want Muter to ignore in the Remove Side Effects mutation operator, such as custom logging functions. Mutants in which these functions aren't called will not be created (note that mutations within the functions themselves are not skipped, only calls to those functions).NOTE: Doesn't support overloading currently - all function calls with a matching name will be skipped.
-
coverageThreshold- when present Muter will ignore files that have a coverage value less than this option. -
testSuiteTimeout- the maximum time in seconds that a test suite is allowed to run before being terminated. This prevents mutations from causing infinite loops or hanging tests. If not specified, tests will run without a timeout.
Below is an example pulled directly from the ExampleApp project.
The configuration file will end up looking something like this:
arguments:
- -project
- ExampleApp.xcodeproj
- -scheme
- ExampleApp
- -sdk
- iphonesimulator
- -destination
- platform=iOS Simulator,name=iPhone 8
- test
executable: /usr/bin/xcodebuild
exclude:
- AppDelegate.swift
Check out the muter.conf.yml in the root directory of this repository for another example.
Xcode Setup
After creating your configuration:
- Add a run script step to the build target.
- **Add the Muter Xcode command
Related Skills
node-connect
346.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
