Skip to content

Instantly share code, notes, and snippets.

@bootstraponline
Last active December 19, 2015 21:58
Show Gist options
  • Save bootstraponline/6023574 to your computer and use it in GitHub Desktop.
Save bootstraponline/6023574 to your computer and use it in GitHub Desktop.
Parallel minitest
require 'rubygems'
$at_once = '3'
$total = 6
ENV['N'] = $at_once
require 'selenium-webdriver'
require 'minitest'
require 'minitest/hell'
require 'minitest/autorun'
$count = 0
class TestRandom2 < Minitest::Test
1.upto($total) do |n|
define_method("test_#{n}") do
thread = Thread.new do
Thread.current.abort_on_exception = true
wd = Selenium::WebDriver.for :firefox
$stdout.puts "\nWEBDRIVER ##{ $count += 1 }\n"
$stdout.puts '~~~~~'
wd.quit
end
thread.join
end
end
end
# Run with: ruby parallel.rb
# requires minitest 5.0.6 or better.
# gem install minitest
require 'rubygems'
ENV['N'] = '10' # run 10 tests in parallel
require 'minitest'
require 'minitest/hell'
require 'minitest/autorun'
def random_code
sleep 1 # sleep so we can visually see that tests complete in batches of 10
assert_equal(Random.rand(2), 1)
end
module TestRandom
# run the same test 100 times by defining 100 methods
# using the contents of one test
1.upto(100) do |n|
define_method("test_#{n}") do
random_code
end
end
end
class TestRandom2 < Minitest::Test
include TestRandom
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment