Ruby on Rails development from scratch (Windows) (29)-Performance testing

Source: Internet
Author: User
Tags require ruby on rails

Rails is for Web projects and you have to think about the large amount of traffic, so let's take a look at how rails performs performance testing.

1. To perform performance testing, we first have to imitate a large number of data, we now know that in the test/fixtures/directory in the Yml file to add our test data, when the test run, the data will be loaded into the database. But a piece of two data can also, the case of many data, a piece in the Yml file can not write, so, we first see how to create a lot of data in the Yml file. Create a subdirectory in the Fixtrue directory performance, add a new order.yml file inside, and change the contents to the following:

# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
<% for i in 1..100%>
order_<% = i%>:
ID: <%= i%>
name:fred
email:fred@flintstones.com
address:123 rockpile circle< c7/> pay_type:check
<% End%>

And then run one of our empty tests, order_test.rb

Depot>ruby test/unit/order_test.rb

To the database to view the following table order, which has already initialized 100 records. The reason we want to create a new performance directory is because we don't want to run each test to initialize 100 records, and the records in that order.yml file that we used to test model and controller were enough.

2. Create a performance directory under the test directory and create a ORDER_TEST.RB file that reads as follows:

Require File.dirname (__file__) + '/... /test_helper '
require ' Store_controller '
class Ordertest < Test::unit::testcase fixtures
:p roducts
how_many =
def setup
@controller = storecontroller.new
@request = actioncontroller::testrequest . New
@response = Actioncontroller::testresponse.new
Get:add_to_cart,: ID => 1
end
def teardown   
order.delete_all
End
def test_save_bulk_orders
elapsedseconds = Benchmark::realtime
do Fixtures.create_fixtures (File.dirname (__file__) +
"/... /fixtures/performance ", Orders")
assert_equal (How_many, Order.find_all.size)
1.upto (how_many) do |id|< c20/> order = order.find (ID)
get:save_order, => order.attributes
Ion => ' index '
assert_equal ("Thank for your order.", Flash[:notice]) end
end
assert Elapsedseconds < 3.0, "actually took #{elapsedseconds} seconds"
end

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.