Web Interface Test Tool--jmeter

Source: Internet
Author: User
Tags http post keep alive

Original: http://www.cnblogs.com/fnng/p/5827577.html

About the JMeter Performance test tool is no longer described too much. If you want to learn software performance testing, then you should have heard about it.

It is highly recommended to read the Official document study: Http://jmeter.apache.org/index.html

Is there a more authoritative, more comprehensive introduction to JMeter tools used?

However, it is used to do interface testing here.

First, install the JMeter

JMeter Official homepage: http://jmeter.apache.org/

There is also a very detailed introduction to what JMeter can do. In addition its documentation is also written in detail. If you want to learn jmeter, then its documentation will be the best textbook.

I believe you can find it on the official website and download it.

JMeter is developed by the Java language, and the latest version of Jmeter3.0 requires a Java 7 or later version of the environment. I also believe you can handle the Java environment.

Next, unzip the downloaded Apache-jmeter-3.0.zip and go to the Unzip directory .../apache-jmeter-3.0/bin. Double-click Apachejmeter.jar to start:

Second, add the HTTP interface Test

Our tools are all done in the JMeter tool, followed by the usual steps to create an HTTP interface test.

For example, right-click on "Test Plan"-"add"-"Threads (Users)" and "Thread group".

For example, to set up a thread group, the thread group consists of three parameters: the number of threads, the length of preparation (ramp-up Period (in seconds)), and the number of cycles.

Number of Threads : Number of virtual users. A virtual user occupies a process or thread. Set how many virtual users here is the number of threads set.

Preparation Time : The number of virtual users set to start all of the time. If the number of threads is 20 and the preparation time is 10 (seconds), it takes 10 seconds to start 20 threads. That is, an average of 2 threads per second is started.

number of Cycles : the number of requests per thread sent. If the number of threads is 20 and the number of cycles is 100, then each thread sends 100 requests. The total number of requests is 20*100=2000. If "Forever" is checked, all threads will continue to send the request until the Stop button on the toolbar is manually clicked, or the thread time of the set ends.

Because the interface test is done here, each parameter is 1.

For example, right-click on "Thread Group"-"Add"-"Sampler"-"HTTP request".

name : This property is used to identify a sampler and it is recommended to use a meaningful name.

Note : For tests that do not have any effect, only users record user-readable comment information.

server name or IP : The destination server name or IP address sent by the HTTP request.

Port Number : The port number of the destination server, the default value is 80.

protocol : The protocol that sends an HTTP request to the destination server, either HTTP or HTTPS, with the default value HTTP.

methods: Methods for sending HTTP requests, including GET, POST, HEAD, PUT, OPTIONS, TRACE, delete, and so on.

Content Encoding : Encoding the contents, the default value is iso8859

path : Destination URL path (excluding server address and port)

Automatic redirection: If this option is selected, JMeter automatically redirects to the new page when the response is 302/301 when the HTTP request is sent.

Use keep Alive : When this option is selected, HTTP communication is used keep-alive between JMeter and the target server, which is selected by default.

Use Multipart/from-data for HTTP POST : When sending an HTTP POST request, it is sent by using the Multipart/from-data method, which is not selected by default.

send parameters with the request: the URL parameter is sent in the request, and for the URL with the parameter, JMeter provides a simple method for parameterization. The user can set all parameters in the URL in this table, and each row in the table is a parameter value pair (the name 1= value 1 in the corresponding Rul).

For example, right-click on "Thread Group"-"Add"-"listener"-"view result tree".

Third, add a new POST request

The POST request is added in the same way as the previous GET request. However, the POST request requires setting parameters.

Server name or ip:127.0.0.1

Port number: 8000

Method: POST

Path:/polls/question_vote/

Send parameters together with the request:

Click the "Add" button to add the parameters for the POST request.

Name:

Value

Qid

1

Cid

1

To perform the test:

Select the menu bar "Run"-"clear", or click the toolbar to clear the button. Then re-execute the startup test. and view the result tree.

Iv. Adding assertions

For automated testing, assertions have to be made, and if there is no assertion that we can only compare the data returned to the interface by the human eye, the assertion function simplifies the process. JMeter provides a wealth of assertion methods to help us do this work.

For example, right-click on the HTTP request "add"-"assert"-"response assertion".

Response fields to test: Response text, Document (text), URL swatch, response information, Response Headers, Lgnore Staus, and more. Although the interface returns JSON-formatted data, the return data is text for JMeter, so you can tick "response text" here.

Pattern matching rules: include, match, Equals, Substring. This only needs to verify that the return data contains the primary keyword, so check "include" here.

The pattern to test: is actually the asserted data. Click the "Add" button to enter the data you want to assert.

To run the test:

Clear the test data again, click Start Test, view results tree, such as.

=====================

Interface testing is so simple!

Web Interface Test Tool--jmeter

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.