Functional tests running very slow when using Factory_Girl
In our Rails project, we decided to eliminate fixtures and use Factory_Girl for our tests instead. We program using TDD so we have plenty of unit and functional tests (Test::Unit). The application has 23 controllers and 14 models, which means that we have plenty of tests.
When we used fixtures testing was faster but we found that they were difficult to mantain (as our model associations began to grow).
Today, TDD is becoming very difficult as running our full test suite takes about 50 seconds (maybe this is not much) :-(
The following is one of the biggest Factories. Maybe there's something wrong with it that makes the object construction run slow...
Factory.define :content do |c| c.sequence(:id) {|n| n } c.title "Don't Make Me Think: A Common Sense Approach to Web Usability, 2nd Edition" c.description "Plain" c.privacy "private" c.category_id 2 c.association :owner, :factory => :user c.file_file_name "file.abc" c.file_file_size 1024 c.file_content_type "application/zip" c.cover_file_name "1.jpg" c.cover_file_size 200 c.cover_content_type "image/jpeg" c.created_at "2010-01-01 00:00:00" c.opinions [] c.creators [] end
Anyone with experience in using Factory_Girl can tell us how to reduce our testing time? Maybe there's something we can improve in our factories definition...开发者_运维问答
Thanks!
Pablo.
We had a very long sample description in our Content's factory. By reducing the length of the test value for this field we've reduce the running time at almost 50%.
We're also asking ourselves if the fact that we're using acts_as_indexed in our Content model slows the execution of the test suite as contents are being indexed as they are created by Factory Girl. What do you think?
Thanks,
Pablo.
精彩评论