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 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
Install
# add to Gemfile
gem "parallel_tests", :group => :development
Setup
1.- Add to your config/database.yml
test:
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: https://github.com/grosser/parallel_tests