Before starting with mutant it's recommended to understand the nomenclature.
To add mutant to your test-unit code base you need to:
-
Add
mutant-test-unitas development dependency to yourGemfileor.gemspecThis may look like:
# A gemfile gem 'mutant-test-unit'
-
Add
require 'mutant/test_unit/coverage'to your test environment (for example to yourtest/test_helper.rb)Example:
require 'test/unit' require 'mutant/test_unit/coverage' class YourTestBaseClass < Test::Unit::TestCase # ...
-
Add
.covercall sites to your test suite to mark them as eligible for killing mutations in subjects.Example:
class YourLibrarySomeClassTest < YourTestBaseClass cover YourLibrary::SomeClass # tells mutant which subjects this test should cover cover 'YourLibrary::SomeClass#some_method' # alternative for more fine-grained control # ...
-
Run mutant against the test-unit integration
First verify tests work with mutant's test runner:
bundle exec mutant test run --include lib --require 'your_library.rb' --integration test-unit
Then run mutation testing:
bundle exec mutant run --include lib --require 'your_library.rb' --integration test-unit -- 'YourLibrary*'
Note: It is recommended to first verify the test suite works with
mutant test runbefore running mutation testing. See the test runner documentation for details.