2013-03-14 63 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