Showing posts with label test. Show all posts
Showing posts with label test. Show all posts

Wednesday, January 26, 2011

Timing your rake test cases in Rails 3: test_benchmark

i was overriding the setup and teardown of ActiveSupport::TestCase in test_helper to time my rake test cases. but in my current project, there are many test cases already overriding the setup method. So, if i still use this way of time tracking, I would have to change too many files.

so, after googling (oh, this google-ing form passes the checkspell ! ) site:github.com, i found test_benchmark. it is super easy to setup.


Include Gem and Rake

if you are using Rails 3, just

  1. add following line to Gemfile (better put it in group :test):
    gem "test_benchmark"
  2. run:
    bundle install
  3. run:
    bundle install
    (or rake test:units if you want to find slow model test cases)

then you can see the top 15 slowest test cases:


Turn it off

you dont want to see all this figures every time you rake test. to switch it off, provide
rake test BENCHMARK=false


Turn it off by default

this is cool gem and some options available to configure.
but actually, i want the other way round.
I want it off by default and turn it on ad-hoc

so i added one line in my test_helper.rb:
Test::Unit::UI::Console::TestRunner.set_test_benchmark_limits(0, 0) unless ENV["SHOW_TIME"]

so now the usage becomes
rake test SHOW_TIME=true



there are some more options there, check out the details at timocratic github:
https://github.com/timocratic/test_benchmark

Tuesday, September 14, 2010

Stress Test Tools

Besides using JMeter for Web Stress Test tools, below is a simple tools under Apache.

1. 同時 10 個連線,連續點擊 10000 次 ( 每個 Request 執行完畢後都會自動斷線,然後再重新連線 )

ab -n 10000 -c 10 http://www.example.com/index.aspx

2. 同時 10 個連線,連續點擊 10000 次,並且使用 Keep-Alive 方式連線(當 Web Server 有支援 Keep-Alive 功能時 ApacheBench 會在同一個連線下連續點擊該網頁)

ab -n 10000 -c 10 -k http://www.example.com/index.aspx

3. 將測試的效能原始資料匯出成 CSV 檔

ab -e output.csv -n 10000 -c 10 http://www.example.com/index.aspx



http://blog.miniasp.com/post/2008/06/Using-ApacheBench-ab-to-to-Web-stress-test.aspx