2012-06-15 35 views
4

我的工作轨道上的3.1.1和使用socery 0.7.11进行验证,我需要实现性能测试中,我可以测试下面的事情如何启动性能测试

  • 模拟100个用户签约同时开启和关闭
  • 模拟100位用户同时添加新兴趣。

我必须经过以下环节:

http://rubylearning.com/blog/2011/08/14/performance-testing-rails-applications-how-to/

http://guides.rubyonrails.org/performance_testing.html

而且能够做以下的事情

  • 创建的测试文件夹test_helper.rb中
  • 创建测试/性能/ login_test.rb
  • 创建夹具/ users.yml里

test_helper.rb中

ENV["RAILS_ENV"] = "test" 
require File.expand_path('../../config/environment', __FILE__) 
require 'rails/test_help' 

class ActiveSupport::TestCase 
    # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. 
    # 
    # Note: You'll currently still have to declare fixtures explicitly in integration tests 
    # -- they do not yet inherit this setting 
    fixtures :all 

    # Add more helper methods to be used by all tests here... 
end 

/performance/login_test.rb

require 'test_helper' 
require 'rails/performance_test_help' 

class LoginTest < ActionDispatch::PerformanceTest 

    fixtures :users 
    # Refer to the documentation for all available options 
    self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory], 
          :output => 'tmp/performance', :formats => [:flat] } 

    def test_login 
    post_via_redirect "http://bc.lvh.me/", :username => users(:youruser).username, :password => users(:youruser).password 
#using lvh.me coz login page is on my subdomain 
    end 
end 

夹具/ users.yml里

one: 
    username: eagleschasar12 
    password: chaitanyA1# 

two: 
    username: eaglesmarktell12 
    password: chaitanyA1# 

当我运行耙测试:个人资料,我得到了以下结果

E 
=============================================================================== 
Error: test_login(LoginTest) 
ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has no column named password: INSERT INTO "users" ("username", "password", "created_at", "updated_at", "id") VALUES ('eagleschasar12', 'chaitanyA1#', '2012-06-15 06:43:01', '2012-06-15 06:43:01', 980190962) 

所以我的问题是

  • 为什么测试命令发射插入查询?
  • 我是否需要在夹具文件中写入100条用户记录以测试功能?
  • 如何检查会话登录/注销?
  • 另外,当我从数据库中选择兴趣类型时,我的用户应该登录系统,那么如何在性能测试中测试这种情况?
  • 此测试是否在webrick上运行,这是我的本地服务器。

回答

1

我会尽量回答你的问题,以尽我所能。我相信其他人会给予更多的完整的答案为每一个单独和他们是欢迎的,但我希望让你开始这样你就可以知道要寻找什么:


1.为什么测试命令发射插入查询?

你插入查询从固定装置中运行。我个人用户FactoryGirl,但逻辑是相同的。当你运行你的灯具时,它会将该对象插入到你的数据库中。这样,您可以执行诸如fixture :user之类的操作,它将为您创建一个用户,而无需每次都提供所有用户对象的详细信息。如果你的文件中有5个灯具,运行如fixture :users将创建5个条目(如果有人可以证实这一点对于灯具,我会很感激,因为我没有用户装置)。


2.我是否需要在夹具文件中写入100条记录来测试功能?

不,你不会。您可以使用Faker gem自动创建尽可能多的用户(或其他任何东西),只要你想用随机的名字,字符串等文档是here


3.如何检查会话登录/注销?

当您创建会话时,您应该设置session[user_id]变量,以便您可以对此进行测试。不用说,在注销(即会话销毁)时,您应该将其设置为nil。在任何情况下,当通过设置session[:user_id]变量,创建一个会话,那么你就可以访问使用request.session_options[:id]


4.此外,当我从我的分贝用户选择感兴趣的类型应该在系统中记录的会话ID,那么我如何在性能测试中测试这种情况?

每个应该运行“test_log_in”功能,在您创建测试用户登录测试之前。然后,需要登录用户的测试才能通过。您还应该在不登录测试用户的情况下创建测试,并且不应执行需要登录用户的更改(或不应显示页面)。


5.此测试是否在我的本地服务器webrick上运行?

如果这是你已经安装在你的Gemfile服务器,它会被使用。它将与您安装的任何服务器一起工作。


你已经问了很多的一个问题的问题,所以如果你需要的答案更详细的我建议你问的每个问题在不同的岗位上更详细的说明,你在找什么对于。这样你的答案就不会像这样广泛,但更具体。

希望我至少给你一个好地方,从启动。

+1

是的,你是正确的下一次,我会照顾好这个(约合问一个问题),非常感谢给我一个方向 – chaitanya