需单独安装对应测试框架的集成 gem(如 mutant-rspec),主 gem 不含集成;开源仓库必须加 --usage opensource,商业使用需付费订阅;仅支持 Linux 和 macOS,不支持 Windows
mutant
mbj活跃维护Ruby 的变异测试工具,通过自动改写代码来检验测试是否真能发现问题,专治测试覆盖率虚高、断言不严的情况。
Mutation testing for Ruby. AI writes your code. AI writes your tests. But who tests the tests?
gem install mutant-rspec
mutant run --use rspec --usage opensource --require ./lib/person 'Person#adult?'README 未说明
Ruby 变异测试工具,通过系统改写代码验证测试是否真能捕获每个变更
Ruby 的变异测试工具,通过自动改写代码来检验测试是否真能发现问题,专治测试覆盖率虚高、断言不严的情况。
核心能力
- 系统化变异代码并检验测试能否捕获每处改动
- 覆盖算术、逻辑、位运算、语句删除、返回值等多种变异算子
- 记录每次运行到 .mutant/results/ 并保留最近 100 次会话
- 支持 RSpec、Minitest、Test::Unit 三种测试框架集成
- 支持 Rails 应用及并行 worker 的数据库隔离
容易踩的坑
- v0.16.2最新正式版2026-04-21 · 2026-04-21 01:12 UTC
- Fix crash on non-UTF-8 / binary log output
- v0.16.02026-04-07 · 2026-04-07 17:47 UTC
查看更新说明
Changes
- Add integer overflow boundary mutations
- Add session recording support
- Add improved session CLI with subject drilldown
- Remove Concord dependency
- Remove Ruby 3.2 support
- Relax unparser dependency to allow versions < 0.10
- Update unparser to 0.9.0
- Add gem push workflow with Sigstore attestation
- v0.15.12026-03-12 · 2026-03-12 01:35 UTC
查看更新说明
-
Add alive mutation explanation to CLI report output. When alive mutations are present, the report now prints guidance explaining the two actions: keep the mutated code or add the missing test. This is helpful to improve agent behavior when processing mutant reports.
-
Add alive mutation explanation to README and documentation.
-
Remove mutant rust wrapper stub. The rust wrapper is canceled in favor of a spiritual successor to mutant.
-
- v0.15.02026-02-26 · 2026-02-26 17:23 UTC
查看更新说明
-
Add operator mutations.
-
#1523 #1530 Add arithmetic operator swap mutations (
+↔-,*↔/). Multiplication/division skips multiplicative identity operands. -
#1527 Add
==↔!=swap mutation. -
#1534 Add logical operator swap mutations (
and↔or,&&↔||). -
#1535 #1576 Add compound assignment operator swap mutations (
+=↔-=,*=↔/=,%=→/=,**=→*=,&=↔|=↔^=,<<=↔>>=,&&=↔||=).
-
-
Add selector replacement mutations.
Orthogonal replacements (circular swaps):
- #1559
select/filter↔reject - #1560
any?↔none? - #1561
take↔drop - #1562
append/push↔prepend/unshift - #1563
positive?↔negative? - #1564
zero?↔nonzero? - #1565
count↔size/length - #1568
keys↔values - #1571
even?↔odd?,min↔max,min_by↔max_by - #1573
all?↔none?,floor↔ceil,start_with?↔end_with?,transform_keys↔transform_values,upcase↔downcase - #1576
pop↔shift,each_key↔each_value,assoc↔rassoc,succ↔pred,chars↔bytes,empty?↔any?,grep↔grep_v
Semantic reductions:
- #1542 Bang → non-bang methods
(e.g.
map!→map,sort!→sort,compact!→compact). - #1567
#1572 Enumerable reductions
(
collect→each,each_with_object→each,each_with_index→each,each_cons→each,each_slice→each,sample→first/last,sort_by→sort). - #1574
filter_map→map,delete_if→reject,keep_if→select,collect_concat→collect,chunk/chunk_while/slice_before/slice_after/slice_when→each,strip→lstrip/rstrip,to_f→to_i,defined?→true, strip regexpm(multiline) flag.
- #1559
-
Add pattern-matching mutation support. Dedicated mutators for
case/inexpressions,inpatterns, match alternatives (A | B), and pattern match predicates (x in pattern→false). Guard clauses in pattern matches are now mutated. -
Add control flow mutations.
while↔untilorthogonal swap mutations.while_postanduntil_postsupport forbegin...end while/begin...end untilconstructs. -
Add
super↔super()mutation operators to test implicit vs explicit argument forwarding. -
Add rescue clause removal mutations. When multiple rescue clauses exist, emit mutations that remove each clause individually.
-
Add inline rescue modifier mutations (
foo rescue bar→bar). -
[#1
-
- v0.14.22026-02-20 · 2026-02-20 23:47 UTC
查看更新说明
What's Changed
- Fix coverage percentage rounding up to 100% when mutations survive by @sferik in https://github.com/mbj/mutant/pull/1512
- Change to allow builds by other peoples PRs by @mbj in https://github.com/mbj/mutant/pull/1513
- Add visual progress bar for TTY output by @sferik in https://github.com/mbj/mutant/pull/1514
- Add bitwise operator mutations by @sferik in https://github.com/mbj/mutant/pull/1516
- Change version to v0.14.2 by @mbj in https://github.com/mbj/mutant/pull/1517
- Add improved quick start documentation by @mbj in https://github.com/mbj/mutant/pull/1519
- Fix readme badge by @mbj in https://github.com/mbj/mutant/pull/1520
Full Changelog: https://github.com/mbj/mutant/compare/v0.14.1...v0.14.2
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
mutant
What is Mutant?
AI writes your code. AI writes your tests. But who tests the tests?
Copilot, Claude, and ChatGPT generate code faster than humans can review it. They'll even write tests that pass. But passing tests aren't the same as meaningful tests.
Mutant is mutation testing for Ruby. It systematically modifies your code and verifies your tests actually catch each change.
The more code AI writes for you, the more you need verification you can trust.
What is an Alive Mutation?
Each surviving (alive) mutation is a call to action with exactly one of two options:
- Keep the mutated code - your tests already specify the correct semantics, and the original code is redundant. Accept the mutation as a simplification.
- Add the missing test - the original code is correct, but the tests don't verify the behavior the mutation removed.
Author
Mutant was created and is developed by Markus Schirp. It is the subject of IEEE-published research and is included in the Trail of Bits Ruby Security Field Guide.
Quick Start
# lib/person.rb
class Person
def initialize(age:)
@age = age
end
def adult?
@age >= 18
end
end
# spec/person_spec.rb
RSpec.describe Person do
describe '#adult?' do
it 'returns true for age 19' do
expect(Person.new(age: 19).adult?).to be(true)
end
it 'returns false for age 17' do
expect(Person.new(age: 17).adult?).to be(false)
end
end
end
Tests pass. But run mutant:
gem install mutant-rspec
mutant run --use rspec --usage opensource --require ./lib/person 'Person#adult?'
Mutant finds a surviving mutation indicating a shallow test:
def adult?
- @age >= 18
+ @age > 18
end
Your tests don't cover age == 18. The mutation from >= to > doesn't break them.
This is just one of many mutation operators. Mutant also mutates arithmetic, logical, bitwise operators, removes statements, modifies return values, and more.
A full working example is available in the quick_start directory.
Session History
Mutant records every run to .mutant/results/, and keeps the 100 most recent.
You can recall past results without re-running mutation testing:
# List past sessions (most recent first)
mutant session list
# Show full report from the latest session
mutant session show
# Show full report from a specific session
mutant session show --session-id 019cf6f1-77e8-74b6-82db-f8b5faf570cd
# List subjects with alive/total mutation counts
mutant session subject
# Show alive mutations for a specific subject
mutant session subject 'Foo::Bar#baz'
# Remove old or incompatible session files
mutant session gc --keep 50
Next Steps
- Learn the nomenclature (subjects, mutations, operators)
- Set up your integration: RSpec, Minitest, or Test::Unit
- Run mutant on CI in incremental mode
Ruby Versions
Mutant is supported on Linux and macOS.
| Version | Runtime | Syntax | Mutations |
|---|---|---|---|
| 3.2 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 3.3 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 3.4 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| 4.0 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Rails
Mutant runs against Rails applications, including parallel-worker database isolation (PostgreSQL and SQLite). The hook recipes are verified in CI on every non-EOL Rails version:
| Version | Status |
|---|---|
| 7.2 | :heavy_check_mark: |
| 8.0 | :heavy_check_mark: |
| 8.1 | :heavy_check_mark: |
See the Rails Integration guide for setup, eager loading, and per-worker database isolation. A runnable, CI-verified example lives in rails_example.
Licensing
Free for open source. Use --usage opensource for public repositories.
Commercial use requires a subscription ($30/month or $250/year per developer). Enterprise — reach out directly. See commercial licensing for pricing and details.
Documentation
- Configuration
- RSpec Integration
- Minitest Integration
- Test::Unit Integration
- Rails Integration
- Incremental Mode
- Test Selection
- Reading Reports
- Concurrency
- AST Pattern Matching
- Session JSON Schema
- Hooks
- Sorbet
- Nomenclature
- Limitations
- Mutant in the Wild
Communication
Contributing
See CONTRIBUTING.md for development setup and guidelines.
Acknowledgments
- Contributors
- The
mutant-minitestintegration was sponsored by Arkency