Top Related Projects
minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.
RSpec runner and formatters
Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites
A Ruby static code analyzer and formatter, based on the community Ruby style guide.
A library for setting up Ruby objects as test data.
Library for stubbing and setting expectations on HTTP requests in Ruby.
Quick Overview
Mutant is a mutation testing tool for Ruby. It helps developers improve their test suites by introducing small changes (mutations) to the source code and checking if the tests can detect these changes. This process helps identify weak spots in test coverage and encourages more robust test writing.
Pros
- Improves test suite quality and coverage
- Helps identify untested or poorly tested code paths
- Supports multiple Ruby versions and testing frameworks
- Provides detailed reports and metrics on mutation coverage
Cons
- Can be time-consuming for large codebases
- May produce false positives in certain scenarios
- Requires careful configuration to avoid excessive runtime
- Learning curve for interpreting and acting on mutation results
Code Examples
- Basic configuration in a Ruby project:
# Gemfile
gem 'mutant'
gem 'mutant-rspec'
# .mutant.yml
integration:
name: rspec
includes:
- lib
requires:
- my_project
- Running Mutant from the command line:
bundle exec mutant run --include lib --require my_project --use rspec 'MyProject*'
- Using Mutant with a specific Ruby file:
require 'mutant'
Mutant::CLI.run(['run', '--include', 'lib', '--require', 'my_project', 'MyProject::SpecificClass'])
Getting Started
-
Add Mutant to your Gemfile:
gem 'mutant' gem 'mutant-rspec' # or mutant-minitest, depending on your test framework
-
Create a
.mutant.yml
configuration file in your project root:integration: name: rspec includes: - lib requires: - your_project_name
-
Run Mutant from the command line:
bundle exec mutant run 'YourProject*'
-
Analyze the output and improve your tests based on the mutation results.
Competitor Comparisons
minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.
Pros of Minitest
- Lightweight and fast, with minimal setup required
- Built-in support for Ruby's standard library
- Simple and intuitive syntax for writing tests
Cons of Minitest
- Limited mutation testing capabilities
- Less comprehensive code coverage analysis
- Fewer advanced features for complex testing scenarios
Code Comparison
Minitest example:
require 'minitest/autorun'
class TestExample < Minitest::Test
def test_addition
assert_equal 4, 2 + 2
end
end
Mutant example:
class Calculator
def add(a, b)
a + b
end
end
Mutant::CLI.run(['--include', 'lib', '--require', 'calculator', 'Calculator#add'])
Mutant focuses on mutation testing, automatically generating and testing code mutations to ensure thorough test coverage. Minitest, on the other hand, provides a simpler framework for writing and running tests without built-in mutation testing capabilities.
Mutant offers more advanced features for detecting edge cases and improving test quality, while Minitest excels in simplicity and ease of use for basic testing needs. The choice between the two depends on the project's complexity and testing requirements.
RSpec runner and formatters
Pros of RSpec-Core
- Widely adopted and well-established testing framework for Ruby
- Extensive documentation and community support
- Intuitive, expressive syntax for writing tests
Cons of RSpec-Core
- Slower test execution compared to Mutant
- Limited built-in mutation testing capabilities
- Requires additional setup for advanced testing scenarios
Code Comparison
RSpec-Core example:
describe Calculator do
it "adds two numbers" do
calc = Calculator.new
expect(calc.add(2, 3)).to eq(5)
end
end
Mutant example:
class Calculator
def add(a, b)
a + b
end
end
Mutant::CLI.run(%w[--include lib --require calculator Calculator])
RSpec-Core focuses on behavior-driven development (BDD) and provides a readable syntax for writing tests. It's widely used in the Ruby community and offers extensive documentation and plugins.
Mutant, on the other hand, is a mutation testing tool that automatically modifies your code to ensure your tests catch all possible edge cases. It's more focused on code coverage and finding potential bugs that traditional testing might miss.
While RSpec-Core is easier to get started with and has a larger ecosystem, Mutant offers more advanced testing capabilities, particularly in identifying untested edge cases and improving overall code quality.
Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites
Pros of SimpleCov
- Easier to set up and use, with minimal configuration required
- Provides clear, HTML-based reports for code coverage
- Integrates well with various Ruby testing frameworks
Cons of SimpleCov
- Limited to code coverage analysis, lacking advanced mutation testing features
- May not catch logical errors or ineffective tests as effectively as mutation testing
- Can sometimes produce false positives in coverage reports
Code Comparison
SimpleCov setup:
require 'simplecov'
SimpleCov.start
# Your tests go here
Mutant setup:
require 'mutant'
Mutant::CLI.run(%w[
--include lib
--require my_project
--use rspec
MyProject*
])
Key Differences
- SimpleCov focuses on code coverage, while Mutant performs mutation testing
- Mutant provides more in-depth analysis of test effectiveness
- SimpleCov generates user-friendly HTML reports, whereas Mutant outputs detailed console results
- Mutant requires more setup and configuration compared to SimpleCov
- SimpleCov is generally faster to run, while Mutant's analysis is more time-consuming but potentially more thorough
Both tools serve different purposes in the testing ecosystem, with SimpleCov offering quick insights into code coverage and Mutant providing deeper analysis of test effectiveness through mutation testing.
A Ruby static code analyzer and formatter, based on the community Ruby style guide.
Pros of RuboCop
- Focuses on style and best practices enforcement
- Extensive configuration options for customization
- Large community and wide adoption in Ruby projects
Cons of RuboCop
- Can be overly opinionated, leading to false positives
- Performance can be slow on large codebases
- Limited to static code analysis, doesn't test runtime behavior
Code Comparison
Mutant example (mutation testing):
def add(a, b)
a + b
end
# Mutant might generate:
def add(a, b)
a - b
end
RuboCop example (style enforcement):
# Bad style
def some_method( x,y )
x+y
end
# RuboCop suggestion
def some_method(x, y)
x + y
end
Key Differences
- Mutant focuses on mutation testing to improve test coverage
- RuboCop emphasizes code style and best practices
- Mutant helps identify missing or weak tests
- RuboCop ensures consistent coding style across projects
Both tools serve different purposes in the Ruby ecosystem. Mutant is valuable for improving test quality, while RuboCop helps maintain consistent and clean code. Using both can significantly enhance Ruby project quality and maintainability.
A library for setting up Ruby objects as test data.
Pros of Factory Bot
- Widely adopted and well-established in the Ruby community
- Simplifies test data creation with a clean, intuitive API
- Extensive documentation and community support
Cons of Factory Bot
- Limited to test data generation, not a full mutation testing framework
- May encourage overuse of factories, leading to slower tests
Code Comparison
Factory Bot:
FactoryBot.define do
factory :user do
name { "John Doe" }
email { "john@example.com" }
end
end
Mutant:
class User
def initialize(name, email)
@name = name
@email = email
end
end
Key Differences
- Purpose: Factory Bot focuses on test data generation, while Mutant is a mutation testing tool
- Scope: Factory Bot is specific to testing, Mutant analyzes code quality and test coverage
- Usage: Factory Bot is used in test files, Mutant runs as a separate process to evaluate tests
When to Choose
- Use Factory Bot for creating test data and fixtures in Ruby projects
- Choose Mutant for improving test quality and identifying untested code paths
Both tools serve different purposes in the Ruby ecosystem and can be used complementarily in a project to enhance testing and code quality.
Library for stubbing and setting expectations on HTTP requests in Ruby.
Pros of WebMock
- Focused specifically on HTTP request stubbing and mocking
- Simpler setup and usage for web-related testing scenarios
- Extensive integration with popular HTTP libraries
Cons of WebMock
- Limited to HTTP mocking, less versatile for general-purpose testing
- May require additional tools for comprehensive test coverage
- Less emphasis on mutation testing and code quality improvement
Code Comparison
WebMock example:
stub_request(:get, "www.example.com").
to_return(status: 200, body: "stubbed response", headers: {})
Mutant example:
class Calculator
def add(a, b)
a + b
end
end
Mutant::CLI.run(['Calculator#add'])
Summary
WebMock is a specialized tool for HTTP request mocking, making it ideal for web-related testing scenarios. It offers simpler setup and usage for these specific cases. However, it's limited in scope compared to Mutant, which provides more comprehensive mutation testing and code quality analysis. WebMock focuses on verifying HTTP interactions, while Mutant aims to improve overall code quality by identifying potential bugs and edge cases through mutation testing.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
mutant
What is Mutant?
An automated code review tool, with a side effect of producing semantic code coverage metrics.
Think of mutant as an expert developer that simplifies your code while making sure that all tests pass.
That developer never has a bad day and is always ready to jump on your PR.
Each reported simplification signifies either:
A) A piece of code that does more than the tests ask for. You can probably use the simplified version of the code. OR:
B) If you have a reason to not take the simplified version as it violates a requirement: There was no test that proves the extra requirement. Likely you are missing an important test for that requirement.
On extensive mutant use A) happens more often than B), which leads to overall less code enter your repository at higher confidence for both the author and the reviewer.
BTW: Mutant is a mutation testing tool, which is a form of code coverage. But each reported uncovered mutation is actually a call to action, just like a flag in a code review would be.
Getting started:
- Start with reading the nomenclature. No way around that one, sorry.
- Then select and setup your integration, also make sure you can reproduce the examples in the integration specific documentation.
- Use mutant during code reviews and on CI in incremental mode.
- Do not merge code with new alive mutations. If you really must bypass: Add the subjects with open problems to the ignored subjects.
Operating Systems
Mutant is supported and tested under Linux and Mac OS X.
Ruby Versions
Mutant supports multiple ruby versions at different levels:
- Runtime, indicates mutant can execute on a specific Ruby Version / implementation.
- Syntax, depends on Runtime support, and indicates syntax new to that Ruby version can be used.
- Mutations, depends on Syntax support, and indicates syntax new to that Ruby version is being analysed.
Supported indicates if a specific Ruby version / Implementation is actively supported. Which means:
- New releases will only be done if all tests pass on supported Ruby versions / implementations.
- New features will be available.
Implementation | Version | Runtime | Syntax | Mutations | Supported |
---|---|---|---|---|---|
cRUBY/MRI | 3.1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
cRUBY/MRI | 3.2 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
cRUBY/MRI | 3.3 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
jruby | TBD | :email: | :email: | :email: | :email: |
mruby | TBD | :email: | :email: | :email: | :email: |
cRUBY/MRI | < 3.1 | :no_entry: | :no_entry: | :no_entry: | :no_entry: |
Labels:
- :heavy_check_mark: Supported.
- :warning: Experimental Support.
- :soon: Active work in progress.
- :email: Planned, please contact me on interest.
- :no_entry: Not being planned, or considered, still contact me on interest.
Licensing
Mutant is commercial software, with a free usage option for opensource projects. Opensource projects have to be on a public repository.
Commercial projects have to pay a monthly or annual subscription fee.
Opensource usage
Usage is free and does not require a signup. But it requires the code is under an
opensource license and public. Specify --usage opensource
on the CLI or usage: opensource
in the config file.
Commercial usage
Commercial use requires payment via a subscription and requires a signup. See pricing for available plans.
After payment specify --usage commercial
on the CLI or usage: commercial
in the config file.
Pricing
Mutant is free for opensource use!
For commercial use mutants pricing is subscription based.
Currency | Duration | Cost | Payment Methods |
---|---|---|---|
USD | 1 month | 90$ | Credit Card |
USD | 1 year | 900$ | Credit Card, ACH transfer |
EUR | 1 month | 90⬠| Credit Card, SEPA Direct Debit |
EUR | 1 year | 900⬠| Credit Card, SEPA Direct Debit, SEPA Transfer |
Costs are per developer using mutant on any number of repositories.
Volume subscriptions with custom plans are available on request.
Should you want to procure a commercial mutant subscription please mail me to start the payment process.
Please include the following information:
- Your business invoice address.
- A payment email address, if different from your email address.
- Only for the EU: A valid VAT-ID is required, no sales to private customers to avoid the horrors cross border VAT / MOSS. VAT for EU customers outside of Malta will use reverse charging.
Also feel free to ask any other question I forgot to proactively answer here.
Also checkout the commercial FAQ.
Topics
- Commercial use / private repositories
- Nomenclature
- Reading Reports
- Limitations
- Concurrency
- Rspec Integration
- Minitest Integration
- Configuration
- Sorbet
Communication
Try the following:
- Discord Channel reach for
@mbj
. - Github Issues
- Release Announcement Mailing List
Sponsoring
Mutant, as published in the opensource version, would not exist without the help of contributors spending lots of their private time.
Additionally, the following features where sponsored by organizations:
- The
mutant-minitest
integration was sponsored by Arkency - Mutant's initial concurrency support was sponsored by an undisclosed company that does currently not wish to be listed here.
Legal
Contents of this repository are maintained by:
Schirp DSO LTD
Director: Markus Schirp
Email: info@schirp-dso.com
Vat-ID: MT24186727
Registration: C80467
Office address:
2, Carob Lane,
Sir Harry Luke Street
Naxxar NXR 2209,
Malta
Registred Address
Phoenix Business Centre,
The Penthouse,
Old Railway Track,
Santa Venera SVR9022,
Malta
Top Related Projects
minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.
RSpec runner and formatters
Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites
A Ruby static code analyzer and formatter, based on the community Ruby style guide.
A library for setting up Ruby objects as test data.
Library for stubbing and setting expectations on HTTP requests in Ruby.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot