Faster Rails Tests

Anyone that has worked on a large rails application knows how long it takes for tests to run. I have this same problem as well. I use the build in testing framework packaged with Rails. One thing I noticed was that the Rails environment seemed to be loading between running unit, functional and integration tests. I felt this was unnecessary if I wanted to run the whole test suite, say for CI purposes, so I created a custom rake task that I use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# lib/tasks/test.rake
require 'rake/testtask'
 
Rake::TestTask.new do |t|
 t.libs << "lib"
 t.libs << "test"
 t.name = "test:ci"
 t.warning = false
 t.verbose = false
 t.test_files = FileList[
 "test/unit/**/*_test.rb",
 "test/functional/**/*_test.rb",
 "test/integration/**/*_test.rb"
 ]
end

This allows me to run all my tests in a single application boot and shave a small amount of time off the full run:

1
bundle exec rake test:ci

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>