我正在使用 rails 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 创建了测试文件夹
- 创建了 test/performance/login_test.rb
- 创建了fixtures/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#
当我运行 rake test:profile 时,我得到以下结果
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 条用户记录来测试功能吗?
- 如何检查会话登录/注销?
- 另外,当我从 db 中选择兴趣类型时,我的用户应该登录系统,那么我如何在性能测试中测试这个场景呢?
- 此测试是否在我的本地服务器 webrick 上运行。