mutest is a mutation testing tool for ruby designed to help audit the thoroughness of your test suite and encourage you to write more robust code.
mutest is a fork of the mutant project with a few minor additions. There are a handful of mutations which have been added, removed, or altered (see the CHANGELOG for details) as well as an inline disable comment system. This means that
mutest allows you to do something like this:
# mutest:disable dont_mutate(me: true) # This line is not mutated because of the significant comment above. mutate(me: true) # This line would continue to be mutated.
mutant project, however, only allows disabling mutations on the method selector level and these subjects must be passed as a command line argument to the
mutest project is effectively identical to
mutant, which is the brainchild and excellent work of Markus Schirp.
Note: Referring to the mutant documentation may be helpful for using
mutest, as it is generally applicable.
How it works
mutest parses your ruby code, inserts modifications, and then runs your test suite. If your test suite still passes after
mutest has mutated your code, you have an alive mutation--meaning your tests do not thoroughly cover the modified part of your code. If your tests fail after the code has been modified, the mutation is killed. This means that your test suite was able to detect the semantic change and provide adequate coverage of that condition.
For full examples and a more detailed explanation of the technique, check out this blog post.
mutest is currently only compatible with
rspec. To install the
rspec integration, run:
$ gem install mutest-rspec
to your Gemfile.
mutest on the entire MyProject namespace
mutest --include lib --require my_project --use rspec 'MyProject*'
mutest on a specific class
mutest --include lib --require my_project --use rspec 'MyProject::Foo'
mutest on a specific class method
mutest --include lib --require my_project --use rspec 'MyProject::Foo.bar'
mutest on a specific instance method
mutest --include lib --require my_project --use rspec 'MyProject::Foo#bar'
mutest on only the changes inside the MyProject namespace since a git revision
mutest --include lib --require my_project --use rspec --since HEAD~1 'MyProject*'
For updates to the project, check out the CHANGELOG!
- Markus Schirp did an amazing job on mutant which this fork is based on.