2013-03-14 53 views
0

我在我的Rails應用程序軌性能測試 - 運行一個測試

駐留在測試/性能/ some_file.rb 因此文件包含幾個方法夫婦的性能測試。我需要運行一個才能獲得好日誌

裏面的文件我有幾個test_ *方法。

有沒有辦法只運行一個性能測試? 我執行:

rake test:benchmark TESTOPTS="--name=test_with_pet_care_job" 

,看起來像我的測試開始,但它凍結出於某種原因 我怎麼能只運行一個測試?

這裏是源文件:

測試/性能/註冊/ parent_full_test.rb

require './test/test_helper' 
require 'rails/performance_test_help' 
require 'benchmark_test_helper' 
require './test/performance/registrations/logging_methods' 

module Registration 
    class ParentFullTest < ActionDispatch::PerformanceTest 
    attr_reader :parent_data 

    include Registrations::LoggingMethods 

    def test_with_pet_care_job 
     registration_step '01 Member should be created' do 
     post registration_submit_path, parent_data[:base_info] 
     end 

     registration_step '02 Job should be posted' do 
     post registration_submit_path, parent_data[:petcare_job] 
     end 
    end 

    def test_with_companion_care_job 
     registration_step '01 Member should be created' do 
     post registration_submit_path, parent_data[:base_info] 
     end 

     registration_step '02 Job should be posted' do 
     post registration_submit_path, parent_data[:companion_care_job] 
     end 
    end 

    def setup 
    refresh_member_data 
    delete logout_path 

    write_to_log("performance test started") 
    end 

    def teardown 
    Account::Member.last.profile.destroy # to clean mongo data 
    end 


    private 

    def refresh_member_data 
    @parent_data = BenchmarkTestHelper.yaml_data(data_file) 
    end 

    def data_file 
    File.join(File.expand_path('..' ,__FILE__), 'data/parent.yml.erb') 
    end 
end 

測試/性能/註冊/ logging_methods.rb

module Registrations 
    module LoggingMethods 

    def registration_step(step_name) 
     before_count = Profile::MemberActivity.count 
     write_to_log(step_name + ' started') 
     yield 
     write_to_log(step_name + ' finished') 
     assert_equal Profile::MemberActivity.count, before_count+1, step_name 
    end 

    def write_to_log(message) 
     Rails.logger.debug message 
    end 
end 

test/benchmark_test_helper.rb

require 'yaml' 

module BenchmarkTestHelper 
    class << self 
    def yaml_data(file_name) 
     YAML.load(ERB.new(File.read(file_name)).result).with_indifferent_access 
    end 
    end 

end 

回答

0
ruby -I test test/performance/some_file.rb --name=test_with_pet_care_job 
+1

在Rails 4,該命令將是:軌-f試驗測試/性能/ some_file.rb --name = test_with_pet_care_job – 2013-03-14 17:44:17

+0

我認爲這是幕後相同的命令。無論如何,我嘗試像你建議的那樣運行它 - 結果是一樣的。看起來像一個錯誤。讓我發佈源代碼 – Vladimir 2013-03-14 20:41:22

+0

Rack :: File headers參數替換Rack 1.5後的cache_control。 加載組測試/性能/註冊/ parent_full_test 開始 註冊:: ParentFullTest#test_with_babysitter_job(718毫秒熱身) process_time:729毫秒 和多數民衆贊成 – Vladimir 2013-03-14 21:08:56