Using JMeter for a Simple Test
Lets see how to run JMeter now. We will conduct a simple test to set up a test plan and stress test a Web application. Before proceeding with the test we need to have a test plan first which will help the Jmeter to perform the testing in steps. There are several elements in a test plan like thread groups, listeners, assertions, sample generating controllers, logic controllers etc. Well, these elements will be described later. One point to remember here is that a test plan must have at least one thread group having all other JMeter elements which is the starting point of a test plan. All of the other threads created by the Jmeter to simulate simultaneous users will be controlled by this thread group. Lets go through the steps now.
Step 1: Start JMeter by running the JMeter.bat file for Windows or the JMeter file on Unix.
Step 2: Create a thread group by right-clicking the Test plan element as shown in the picture below. Now select ADD and then the Thread group option. After selecting the thread group option a thread group element will be created by the Jmeter under Test Plan element. This is to confirm about the number of users to be stimulated by you and the number of times the test plan to be repeated.
The screen after creating the Thread group appears like this.
Following properties can be set as shown below:
Name -- You can give any name to the thread
group.
Number of Threads --
You can enter as many threads to stimulate a load test. A single user is
represented by each Thread so if you wish to simulate a load test with 5 concurrent
users then you need to enter 5 as the value for this property.
Ramp-Up Period -- It indicates the time taken by Jmeter to create all of the threads
needed. If you set 10 seconds as the ramp-up period for 5 threads then the JMeter will take
10 seconds to create those 5 threads. Also by setting its value to 0 all the
threads can be created at
once.
Forever -- If you choose this option then the Jmeter will keep sending
the unspecific requests to the tested application. And if disabled then the test
will be repeated the number of times entered in the Loop Count box.
Loop Count -- By specifying its value Jmeter gets to know that how many
times a test is to be repeated provided that the Forever check box should
be unchecked.
Step 3: Now you need to mention the HTTP request (URL and parameters).
To this right click on the Thread Group node then you need to select
Add -> Sampler -> HTTP Request
as shown in the picture.
The picture below shows the screen of HTTP Request in which you can set some properties as described below. Here address which we have taken for the "Hello World" servlet is http://localhost:8080/examples/servlets/servlet/HelloWorldExample.
The following properties can be set on the HTTP Request screen.
Name -- You should put a descriptive name as a thread
group can have multiple HTTP Request elements.
Server Name or IP -- Mention the server name or the IP address of the machine
which is running the application to be tested.
Port Number -- Give the port number on
which the Web applications run which is usually 80.
Protocol -- Mention the protocol to be used
here i.e. either HTTPS or HTTP.
Method -- The GET or POST method
is to be mentioned
here.
Path -- You need to mention the path of
the resource that will handle this request.
Follow Redirects -- follows redirections, if
any, sent by the Web application.
Parameters -- This option shows the list of parameters sent with
the request. You can add and remove parameters by using Add and Delete buttons.
Send a file with a request -- With the help of this option a file upload
can be simulated to the Web application.
Retrieve all images and Java Applets -- This option is used to download embedded content.
Step 4: Now the format of the results is to be selected to get a page containing the results of every request by right-clicking on the Thread group node then select Add -> Listener -> View Results Tree.
Step 5: Now its time to run the Test plan by selecting Run from the menu and then select Start (or Ctrl-R): Hence The test plan will be repeated 10 times in View Result Tree as shown below.
Step 6: The results can been seen in the Results Tree after the completion of the Test plan. As you can seen in the picture below we have selected the first request in the upper pane and also the request which was generated with the results in the form of an HTML page with the text "Hello World!"
Step 7: JMeter has got an interesting feature which is Add more listeners. You can add a View Results in Table listener to view the requests in tabular form as shown below.
Moreover you can add an Aggregate Report listener to get the summary of run as shown below.
Step 8: To save the test plan for later use select File from the
menu and then Save Test Plan (or Ctrl-S). Its preferable to save the test plan before running it.