How to run multiple Rails unit tests at once How to run multiple Rails unit tests at once ruby ruby

How to run multiple Rails unit tests at once


bundle exec ruby -I.:test -e "ARGV.each{|f| require f}" file1 file1

or:

find test -name '*_test.rb' | xargs -t bundle exec ruby -I.:test -e "ARGV.each{|f| require f}"


I ended up hacking this into my RakeFile myself like so:

Rake::TestTask.new(:fast) do |t|  files = if ENV['TEST_FILES']    ENV['TEST_FILES'].split(',')  else    FileList["test/unit/**/*_test.rb", "test/functional/**/*_test.rb", "test/integration/**/*_test.rb"]  end  t.libs << 'test'  t.verbose = true  t.test_files = filesendRake::Task['test:fast'].comment = "Runs unit/functional/integration tests (or a list of files in TEST_FILES) in one block"

Then I whipped up this bash function that allows you to call rt with an arbitrary list of test files. If there's just one file it runs it as ruby directly (this saves 8 seconds for my 50k loc app), otherwise it runs the rake task.

function rt {  if [ $# -le 1 ] ; then    ruby -Itest $1  else    test_files = ""    while [ "$1" != "" ]; do      if [ "$test_files" == "" ]; then        test_files=$1      else        test_files="$test_files,$1"      fi      shift    done    rake test:fast TEST_FILES=$test_files  fi}


There's a parallel_tests gem that will let you run multiple tests in parallel. Once you have it in your Gemfile, you can just run as ...

bundle exec parallel_test integration/test_*.rb

For me I setup a short rake task to run only the tests I want.