Running your tests in parallel

Have you ever felt like running more than one kind of test at the same time, because your tests take so long or just to earn some extra free time? I looked for a solution to this problem, and I actually found a good one.

The gem is called parallel_test, and, it give us the functionality and the possibility to run in parallel:

  • Unit tests
  • Spec tests
  • Feature tests

You could run the multiple combinations of these as well at the same time and sharing the same test database.

The speed applied to these parallel tests is relative to the hardware in your device, so if you have the latest generation of microprocessors, you should feel a huge difference on performance while running your tests.

Setup for Rails


# add to Gemfile
gem "parallel_tests", :group => :development


1.- Add to your config/database.yml

database: your_project_test<%= ENV['TEST_ENV_NUMBER']%>

2.- Create additional database(s)

rake parallel:create

3.- Copy the development schema (repeat after migrations)

rake parallel:prepare

4.- Run!

rake parallel:test          # Test::Unit
rake parallel:spec          # RSpec
rake parallel:features      # Cucumber

rake parallel:test[1] # force 1 CPU --> 86 seconds rake parallel:test # got 2 CPUs? --> 47 seconds rake parallel:test # got 4 CPUs? --> 26 seconds ...

There's a lot more custom options to this gem, you can read all about it here:

Best Practices
De Código, Café y Cervezas 07 – ¿Somos profesionales?
Fixing Rspec and Cucumber random failures in your Continuous Integration Service
RailsConf 2017 Adventure