Test-Map
Track associated files of executed tests to optimize test execution on file changes.
Test-Map results in a file that maps test files to the files they depend on. You can use this file to run only the tests that are affected by a file change. This is useful when you have a large test suite and want to optimize the time spent running tests. Submit a change request and only run tests that depend on what you changed. Optimizing in such way, the time spent waiting for CI to verify can be reduced to seconds.
Usage
Add test-map to your Gemfile.
$ bundle add test-map
On demand you can adapt the configuration to your needs.
TestMap::Configure.configure do |config|
config.logger = Logger.new($stdout) # default logs to dev/null
config.out_file = 'my-test-map.yml' # default is .test-map.yml
# defaults to [%r{^(vendor|test|spec)/}] }
config.exclude_patterns = [%r{^(libraries|testsuite)/}]
# 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
Minitest
Include test-map in your test helper. Typically you want to include it conditionally so it only generates the test map when needed.
# filename: test/test_helper.rb
# Include test-map after minitest has been required
require 'test_map' if ENV['TEST_MAP']
Run your tests with the TEST_MAP
environment variable set.
$ TEST_MAP=1 bundle exec ruby -Itest test/models/user_test.rb
# or
$ TEST_MAP=1 bundle exec rake test
Rspec
Include test-map in your test helper. Typically you want to include it conditionally so it only generates the test map when needed.
# filename: spec/spec_helper.rb
require 'test_map' if ENV['TEST_MAP']
Run your tests with the TEST_MAP
environment variable set.
$ TEST_MAP=1 bundle exec rspec
Development
$ bundle install # install dependencies
$ bundle exec rake # run testsuite
$ bundle exec rubocop # run linter
Contributing
Bug reports and pull requests are welcome on GitHub.