我們正在Ruby 1.9.3和Rails 3.2.1上開發一個應用程序。爲什麼我在Rails 3.2.1上的`rake test:units`的「啓動時間」很慢?
最近,我們的單元測試在開始時變得遲鈍。調用&執行需要約15秒的時間。一旦我看到「執行測試:單位」,在我看到任何輸出之前還需要10秒。最後,任務完成,測試只需3秒鐘即可執行。
單位測試3秒是可以接受的。 BDD/TDD的25秒加載時間並不現實。
這裏的時候我rake test:units --trace
運行會發生什麼:
** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
** Execute test:prepare
** Execute test:units
我不會懷疑裝載的數據庫架構,然後重新加載,可能是緩慢的一個重要來源。但是,我沒有做任何與我們的單元測試有關的Rakefile
。我可以在哪裏窺視下面發生了什麼?
這是在test/test_helper.rb
頂部什麼:
require 'simplecov'
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
我已經試過:
- 註釋掉
simplecov
,因爲我們只使用我們的CI服務器,而不是在開發過程中(在執行時間沒有什麼區別) - 評論其他的東西,但是這打破了即使執行測試。我不完全確定爲什麼那些其他項目在那裏,因爲我認爲Rails環境會自動加載到「測試」中。
任何有關我在哪裏/如何戳我的頭旁看到的想法?
Rails是否有任何運行遷移的機會,而不僅僅是schema:load
?隨着我們的發展,我們有大量的遷移(~30)。
編輯:
我使用的是2011年模型的MacBook Pro配備8G的內存和酷睿i7 - 不認爲這是我的機器。我見過in this question,在Windows上,require
可能會導致問題。
我也認爲燈具可能是問題,但如果燈具出現問題,測試本身,而不是測試的加載時間,會很慢,對嗎?
編輯2:
由於pchap10k的答案,我認爲它有無關耙 - 它是關於我們的Gemfile
。也許我應該在這方面進行搜索......
似乎就是這樣。 Gemfile需要15秒才能加載Rails環境。 – makdad