Minitest::Retry
Re-run the test when the test fails.
Installation
Add this line to your application's Gemfile:
gem 'minitest-retry'
And then execute:
$ bundle
Or install it yourself as:
$ gem install minitest-retry
Usage
In your test_helper.rb
file, add the following lines:
require 'minitest/retry'
Minitest::Retry.use!
Options can be specified to use!
method. Can specify options are as follows:
Minitest::Retry.use!(
retry_count: 3,
verbose: true,
io: $stdout,
exceptions_to_retry: [],
methods_to_retry: [],
classes_to_retry: []
)
Callbacks
The on_failure
callback is executed each time a test fails:
Minitest::Retry.on_failure do |klass, test_name, result|
end
The on_consistent_failure
callback is executed when a test consistently fails:
Minitest::Retry.on_consistent_failure do |klass, test_name, result|
end
The on_retry
callback is executed each time a test is retried:
Minitest::Retry.on_retry do |klass, test_name, retry_count, result|
end
Example
Minitest::Retry.use!
class Minitest::RetryTest < Minitest::Test
def test_fail
assert false, 'test fail'
end
end
# Running:
[MinitestRetry] retry 'test_fail' count: 1, msg: test fail
[MinitestRetry] retry 'test_fail' count: 2, msg: test fail
[MinitestRetry] retry 'test_fail' count: 3, msg: test fail
F
Finished in 0.002479s, 403.4698 runs/s, 403.4698 assertions/s.
1) Failure:
Minitest::RetryTest#test_fail [test/minitest/sample_test.rb:6]:
test fail
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/y-yagi/minitest-retry.
License
The gem is available as open source under the terms of the MIT License.