Search

Friends

Atomspheric CO2 (PPM)

Archives

Blather

Uptime verified by Wormly.com

22 August 2008

self.use_transactional_fixtures

Fixtures are slow. Even with a small project with hopeless test coverage the tests were taking over a minute. Which possibly doesn't seem like much to hardcore types, but I'm not hardcore.

I finally decided to experiment with using transactional fixtures to speed things up. In theory, I would expect it to work fine. I didn't think nested transactions were a problem. Apparently it doesn't cope with nested transactions (or possibly just certain kinds). However, you can turn it on by default and turn it off for certain tests.

So in your test_helper.rb file you can do this:

class Test::Unit::TestCase
  self.use_transactional_fixtures = true
end

and in your test for some transaction-needy controller you can do this:

class ContactsControllerTest < Test::Unit::TestCase
  self.use_transactional_fixtures = false 
  # Your tests and stuff
end

My test time dropped to 33 seconds from something like 70 seconds. And I am happier and have more time for other things like making tea at work.

Comments

No comments yet.

Leave a comment

Markdown

0.950 seconds