how to write a JMeter test

In this how-to I will explain how to write a simple HTTP GET test with JMeter, that can be used to measure the responsiveness of a web site.

Step 1: Download JMeter

JMeter (an Apache project) requires Java to run. Once downloaded and unpacked, you can execute the UI by running jmeter.bat (windows) or jmeter.sh (linux) in the bin folder.

Step 2: Add thread group

Set the “number of threads” to the number of users you want to simulate. I will use 10. I will leave the ramp-up time to 1 second, and the loop to 1.

jmeter_add_thread_group

Step 3: Add HTTP Request sampler

Right click the thread group you created in step 2, add >> sampler >> http request.

This object will define the actual HTTP request that you want to test, simulating the number of concurrent users defined in step 2.

jmeter_add_http_sampler

Step 4: Add an Aggregate Report listener

Again right click the thread group you created in step 2, add >> listener >> aggregated report

This object will show you the result of your test. Changing the number of concurrent users and the ramp up time, you will get different results in the report. Keep an eye on the 90% 95% and 99% lines. These will give you a good idea of how responsive your site will be under load.

jmeter_results

Step 5: multiple pages

To test multiple pages in the same site, you will need to add more HTTP Request sampler. Those sampler will share the same root address. To avoid having to type the same common configuration in each HTTP Request sampler, add a “HTTP Request defaults” config element. Right click on the Thread Group create in step 2, add >> Config Element >> Http Request Defaults.

This is particularly helpful if you have a test environment and a production environment, and the only difference between the 2 is the root of the address. With a config element you won’t need to change all the HTTP Request listeners

Step 6: add assertions

Suppose you want to verify that a piece of the response is actually contained in the page under test. Right click one of your HTTP Request sampler, add >> assertions >> Response Assertion. In the object screen, you can add a “Pattern to test” .

To verify that the assertions don’t fail, you will need to add an Assertion Results listener to the HTTP Request sampler, checking the “Log/Display Only” “errors”.

 

Leave a Reply

Your email address will not be published. Required fields are marked *