Track associated files of executed tests to optimize test execution on file changes.
Test-Map records which source files each test touches and caches their checksums. On subsequent runs, tests whose dependencies haven't changed are automatically skipped. This is useful when you have a large test suite and want to optimize the time spent running tests locally or in CI.
Add test-map to your Gemfile.
$ bundle add test-mapInclude test-map in your test helper.
# filename: test/test_helper.rb
# Include test-map after minitest has been required
require 'test_map'Run your tests. On the first run test-map records file dependencies into
.test-map.yml and checksums into .test-cache.yml. On subsequent runs,
tests whose source files haven't changed are automatically skipped.
$ bundle exec ruby -Itest test/models/user_test.rb
# or
$ bundle exec rake testInclude test-map in your spec helper.
# filename: spec/spec_helper.rb
require 'test_map'Run your tests. Caching works the same as with Minitest.
$ bundle exec rspecOn demand you can adapt the configuration to your needs.
TestMap::Config.configure do |config|
config[:logger] = Logger.new($stdout) # default logs to dev/null
config[:merge] = false # merge results (e.g. with multiple testsuites)
config[:out_file] = 'my-test-map.yml' # default is .test-map.yml
config[:cache_file] = 'my-test-cache.yml' # default is .test-cache.yml
# defaults to [%r{^(vendor)/}] }
config[:exclude_patterns] = [%r{^(vendor|other_libraries)/}]
# register a custom rule to match new files; must implement `call(file)`;
# defaults to nil
config[:natural_mapping] = ->(file) { file.sub(%r{^library/}, 'test/') }
end$ bundle install # install dependencies
$ bundle exec rake # run testsuite
$ bundle exec rubocop # run linterBug reports and pull requests are very welcome on GitHub.