JMeter is open source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

Main testing steps:

  • Double click jmeter.bat to open the Jmeter UI.
  • Open xxx.jmx file (test case file)
  • Click green "start" button in toolbar to start running testing.
Brief introduction to use Jmeter
  • HTTP Request Defaults element: define server name or IP and port number in it as follows.

  • HTTP Header Manager element: define some http header variables in it as follows  

  • User Defined Variables element: define some variables that will be used later in our http request.

  • CSV Data Set Config element: get token from csv file

  • Response Assertion element: use it to define how a http request is responded successfully.

  • Other elements: Please refer to Jmeter help document.

  • All elements can be added right-click menu "Add".

  • Test Result: We can check the test results in Summary Report element (result statistics) and View Results Tree element (success or failed).

 

  • All elements can be Enable/Disable via right-click menu to support run or skip run for specific elements.

 

  • How to set up heap for JVM: in Jmeter.bat, set HEAP=-Xms4g -Xmx4g to your wanted size.

  • It's better to test all APIs separately. (i.e. test one API one time)

  • If put json format in Raw Post Body, we need add Content-Type: application/json in HTTP Header Manager, otherwise, define application/json: "" in HTTP Header Manager.


Environment Requirment:

Test sending file in Jmeter:
  • Copy file content to Raw post body, uncheck Use multipart/form-data for post, only content in Raw Post Body will be saved to post stream.
  • Check Use multipart/form-data for POST, add files to "Add File with the Request", those files' content plus some additional header/tail information will be saved to post stream.
  • Use ${__FileToString(fileName,,fileString)} in BeanShell Sampler, put ${fileString} in Raw Post Body, or put ${__FileToString(fileName,,fileString)} in Raw Post Body directly.
  • Add BeanShell Sampler, in Script, add following scripts:
StringfileToString = SendFileUtility.ReadFileToString();

vars.put("FILE_CONTENT",fileToString);

Then put ${FILE_CONTENT}  in Raw Post Body.Copy jar file to jmeter\lib\ext

"SendFileUtility.ReadFileToString()" is implemented in Java.


  • Solutions above work well for text file, but may be don't work for binary file.



posted on 2013-06-03 17:17  chuwachen  阅读(238)  评论(0编辑  收藏  举报