Getting started with JMeter performance testing

Source: Internet
Author: User
Tags jmeter tutorial

Getting started with JMeter performance testing

JMeter is an excellent open-source testing tool, is each senior test engineer, must master the test tools, skilled use of jmeter can greatly improve work efficiency.

Skilled use of jmeter, can use JMeter to fix things, you will not use LoadRunner.

The "Small tank JMeter Tutorial" will cover the various functions of jmeter and will allow readers to quickly master the various uses of JMeter through a rich set of examples.

This article will explain the basic usage of jmeter through a practical test example. The script for this article is provided at the end of this article. Students who do not like reading articles can read the script directly.

Read Catalogue

    1. JMeter Introduction
    2. How to learn JMeter well
    3. JMeter Download and run
    4. Examples of actual tests
    5. First step: New Thread Group
    6. Step Two: Create a new HTTP Request
    7. Step three: Create a new HTTP Header Manager
    8. Fourth step: Create a new View Results Tree
    9. Fifth step: Run the test to see the results
    10. Sixth step: Add assertion and assertion Results
    11. Seventh step: Using user-defined variables
    12. Eighth Step: Association
    13. Source code Download

Jmeter Introduction

Jmeter is a Java-developed, open source, free, test tool used primarily for functional testing and performance testing (stress testing/load testing).

and using JMeter to test the Restful API is very useful.

How to learn JMeter well

If you use JMeter to perform functional testing on the Web, or performance testing. You must be proficient in the HTTP protocol to learn jmeter well. Otherwise it's hard to understand the concept of jmeter.

If you are unfamiliar with the HTTP protocol, you can refer to my "Small tank: HTTP protocol Tutorial"

Jmeter Download and run

Official website: http://jmeter.apache.org/

After decompression, run "Bin/jmeter.bat"

Jmeter is supported in Chinese, after starting Jmeter, click Options, Choose Language to select the language

Examples of actual tests

Goal: Get weather data for the city:

First step: Send request to get city code
Http://toy1.weather.com.cn/search?cityname= Shanghai

Get the city code of Shanghai from the response of this request. Like what:

The area code for Shanghai is 101020100.

The area code for Shanghai Zoo is: 10102010016A

Step two: Send request to: http://www.weather.com.cn/weather2d/101020100.html can get weather data for the city

First step: Create a new thread Group

You must create a new thread group, all tasks for jmeter must be handled by the thread, and all tasks must be created below the thread group.

Step Two: Create a new HTTP Request

For example, I want to send an HTTP request for a GET method: Http://toy1.weather.com.cn/search?cityname= Shanghai

You can fill in this

The third step is to add the HTTP Head Manager

Select the new HTTP request that you created in the previous step. Right-click to create a new HTTP Header manager. Add a header

Fourth step: Add View Results Tree

View Results Tree is used to see the results of the run

Fifth step: Run the test to see the results

to here. We've managed to get it running.

Sixth step: Add assertion and Assert Results

Select HTTP Request, right-add-> assertions, Response assertion. Add Patterns to Test

Then add a assetion Results to see the results of the assertion execution.

Check the thread Group right-click Add-Listener-assertion Results.

After running, if the HTTP response does not contain the expected string. Then test will fail.

7th step: Using user-defined variables

We can also define variables in JMeter.    For example, I define a variable called City. Use it when using ${city}

Add a User Defined Variables. Check the thread Group: Right-click Add, Config Element, User Defined Variables.

We add a variable: City

Then use this variable in the HTTP request

Eighth Step: Association

The so-called Association is the second requst, using the data from the first request

We need to create a new regular expression in the first HTTP requst, extract the value of the response into the variable and provide it to other HTTP request

Select the first HTTP Request, right-click Add, Post processors, Regular expresstion Extractor

Now create a second HTTP Request, send to: http://www.weather.com.cn/weather2d/${citycode}.html

The data in ${citycode} is taken from the regular Expression Extractor

Here, the script is all written, run, and look at the final result.

Getting started with JMeter performance testing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.