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