JMETER

JMETER TEST PLAN

JMETER TEST PLAN

TEST PLAN: test plan is a test case in JMeter. It is a sequence of steps which JMeter will execute upon running. Each test plan is made up of several test elements along with the desired configuration as needed for the performance test. Each element in a test plan is used for a specific operation. JMeter GUI is used to add, remove and configure test plan elements. The left pane of JMeter is used to add a test plan while the right side is used to configure it. A complete test plan consists of one or more components like Thread Groups, logic controllers, sample generating controllers, listeners, timers, assertions, and configuration elements. A minimum of one thread group should be present in every test plan.

WORKBENCH: it’s a temporary place to store elements. Workbench has no relationship with test plan. JMeter does not save the contents of workbench. Only the contents of test plan are saved in JMeter. The primary use of workbench is to store values to be copy pasted to the test plan.

BUILDING A TEST PLAN:

1)Add an Element: 

Right click test plan →Add →select element to add ( for eg thread group)


 

2) Add test element from a file /Load elements -

An element can also be added by loading it from a file and choosing the merge or open option .The loaded element will not be saved by default by JMeter.One has to explicitly save the loaded element by choosing the option “Save selection as”.


3)Remove an element:

To remove an element, select the element, right click on it and select remove.

4) Configure Test Elements:

Test elements can be configured after adding them using controls which are present in the right-side panel.


 

 Figure – Configure a thread group using 10 users with ramp up time 100 sec, loop count 1 and to continue execution upon error.

5) Save test plan:

Test plan can be saved as below: File → Save or File →Save test plan as.


6) Run the test plan: (Control+R)

We can run test plan by choosing any of the two options from below.

  1. Click on play button from top menu. We can also choose to start a test and ignore pauses by selecting “play no pauses” button.


b. Click Start from the Run menu item.

Figure – Start a test from Run menu.

When a test is starts to run it shows a green button at the right end. The numbers to the left of the green button indicate active threads and total threads respectively when run locally. This does not display threads which have been started on remote machine using client server mode.

 

7) Stop a test plan:

 

Test can be stopped by below ways:

a) Stop – (Control +.) will stop thread immediately.

b) Shutdown- (Control+,) will stop at the end of the current work. This does not interrupt active samples.

8) Disable a test plan – it is possible to disable test plan from execution.

Right click on test plan name →Click disable


 

TEST PLAN ELEMENTS:

 

Each JMeter test plan consists of test elements. Test plan must have a minimum of one thread group. Within a thread group we can have a combination of one or more elements. Listed below are popular test plan elements.

  1. Thread Group
  2. Controllers
  3. Listeners
  4. Timers
  5. Configuration Elements
  6. Pre-Processor elements
  7. Post processor elements


Figure - flow diagram depicting test plan elements and their relation with each other

THREAD GROUP:

 Thread group is a group of thread JMeter will use during the test. Thread group element is the starting point of a JMeter test. Thread Groups are used to simulate user action in a performance test. We can have multiple thread groups simulating different types of operations performed by users on an application. Thread group panel is used to configure a thread group.

Name – it is the name of the thread group which suggests the action performed by the users.

Comments – it is an optional text box to add any notes or comments specific to the thread group.

  1. Number of threads: this is used to simulate the number of users or connections to be made to the server
  2. Ramp-up period(In seconds): Time that JMeter will need to start all the threads.
  3. Loop count: Number of iterations, that is the number of times a test is going to be executed. 
  4. Error behaviour: What to do in case of an error: Stop current thread, stop the whole test or continue. 
  5. Scheduler checkbox − Once selected, the Scheduler Configuration section appears at the bottom of the control panel where we can configure the start and end time of the test
  6. Scheduler Configuration – it is used to configure the start and end time of running the test.
  7. Thread Group also allows us to specify the lifetime of the thread. Duration (seconds) and Startup Delay (seconds) to manage the duration of each thread group and after how much seconds it starts can also be configured. When the test is started, JMeter will wait till the time as defined in Startup Delay (seconds) before starting the Threads of the Thread Group and run for the configured Duration (seconds) time.

Once the thread group is configured other test plan elements can be added to the created Thread group like samplers, listener and timers.


 Figure -Thread group screen in JMeter

 Create a thread group in JMeter:

Right click Test plan → Add →Threads (Users) →thread Group

Figure – Create a thread group

Name a thread group:

   Create a thread group as above and add name in the right panel.


Controllers: 

JMeter supports 2 types of controllers which are samplers and Logic Controllers.

Samplers:

Samplers are used to send request to a server and wait for a response. Samplers allow JMeter to send specific type of request to a server. Samplers execute requests based upon the configuration provided. Samplers are executed in the order in which they are defined in the tree. Controllers can be used to define the number of times a sampler request should be repeated. sampler has different properties which can be set up. Samplers can be modified further by adding configuration elements to the test plan. If we want to send the same request to the same server multiple times for testing then it is recommended to use default configuration element in such scenarios. We can also add assertion to the sampler if we wish to perform basic validations on the response. These requests then produce responses which are analysed later. Commonly used samplers are as below:

HTTP Request – HTTPS request is the most popular sampler used for web-based applications. We use this sampler to send HTTP/HTTPS requests to server. 

JDBC Request – This sampler is used to send SQL queries to a database server.

SOAP/XML-RPC Request – This sampler is used to send SOAP requests to a SOAP web service.

Test Action – This is a special type of Sampler, which is used to introduce pauses in a test .This sampler does not send a request to the server

FTP Request – This sampler is used to send file put and get requests to an FTP server.

Below is a list of other samplers provided by JMeter apart from the ones listed above.

  • AJP/1.3 Sampler
  • Access Log Sampler
  • BSF Sampler
  • BeanShell Sampler
  • Debug Sampler
  • JMS Point-to-Point
  • JMS Publisher
  • JMS Subscriber
  • JSR223 Sampler
  • JUnit Request
  • Java Request
  • LDAP Extended Request
  • LDAP Request
  • Mail Reader Sampler
  • OS Process Sampler
  • SMTP Sampler
  • TCP Sampler
  • Test Sampler
  • WebService (SOAP) Request

Configuration of each sampler depends upon the request that it executes. Samplers are added to thread group as below:

Add sampler to a thread group:

Right click Thread Group →Add →Sampler →(as necessary)

Example of the Sampler - a HTTP Request sampler can be added whenever we need to make a POST, GET, or DELETE on a HTTP service.


                Figure – To add samplers to a thread group