Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Jmeter for http Interface Test

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you how to use Jmeter for http interface testing, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Foreword:

It mainly tests the http interface and uses Jmeter tools to realize it.

The Jmter tool was designed for performance testing, and it has been relatively mature in implementing the call to various interfaces. Therefore, this time, we directly use the Jmeter tool to complete the test of the Http interface.

1. The overall plan for developing interface test cases:

Step 1: we need to analyze the test requirements and get the interface documentation provided by the developer

Step 2: sort out the interface test case from the interface description document, which should include detailed input and output parameter data as well as clear format and checkpoints.

Step 3: review the interface test case with the developer.

The fourth step: combined with the development library, prepare the input parameter data and output parameter data in the interface test case, and organize them into a file in csv format.

Step 5: combine the interface test case document and the data file in csv format to do the automatic case development of the interface test case.

2. Applicable scenarios for interface automation:

Currently, the automated interface test case designed has two running scenarios:

1. Test pre-test and development self-test: after the development of a new automated interface test case is completed, it is sent directly to the corresponding development of the interface and arranged to be executed in the local environment of the development. once the development confirms that the interface development is completed, the interface test case begins to be executed. basically, you can get the test results in real time, making it easy for the developer to make a quick judgment. The way to run the developer locally is to open the JMeter tool, import the JMX file, and start executing. ]

two。 Regression testing: after the local test of the development is passed, or the manual test of the whole requirement is passed, the automated interface test cases are classified, the cases that need to be included in the regression test are selected, the test data are reprepared in the continuous integration environment, and the cases are incorporated into the continuous integration job. These interface test cases for regression need to be configured to run automatically on the continuous integration platform.

III. Preparation of interface test environment

Jdk1.6 or above: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Jmeter, download address: http://jmeter.apache.org/download_jmeter.cgi

Download and install the plug-in at http://www.jmeter-plugins.org/

Fourth, create a project:

1. Open Jmeter: after downloading Jmeter, double-click the jmeter.bat file in the bin directory:

2. Add thread group: right-click on "Test Plan"-> add-- > threads (Users)-> Thread Group to add the test scenario setting component. In the interface test, the number of threads is generally set to 1, and the number of cycles is set according to the number of test data.

3. Add "HTTP Cookie Manager":

4. Add the "Http request default value" component, which is easy to use when the system under test has a unique access domain name and port:

5. On the "HTTP request default value" component configuration page, fill in the domain name and port of the system under test, the version of the implementation package of the http request and the specific protocol type. All "HTTP Sampler" in the thread group can use this setting by default.

6. Add the Sampler of "HTTP request" to "thread group"

7. On the HTTP request settings page, enter the details of the API under test, including the request path, the corresponding request method, and the parameter list sent with the request:

8. Set checkpoint: add "response assertion" to the "HTTP request" corresponding to the interface under test.

9. Add a regular expression to the corresponding result on the settings page to judge the existence of the regular expression:

10. Add listeners: it is easy to view the results after running.

Running result:

The above steps complete the creation of a simple test case, and the complex test cases are extended on this basis. For interface test cases developed using Jmeter tools, a subsystem is recommended to be placed in the same "test plan", and process tests can be distinguished by "thread groups", which makes it easy to set different numbers of test data. More independent interfaces can be uniformly placed in a thread group to complete the test sequentially.

Testing of procedural interfaces: if the interfaces to be tested can form a process, you only need to add multiple "HTTP requests" Sampler sequentially, and each request can extract the data that needs to be passed in the context as parameters to ensure the consistency of the data in the process.

On how to use Jmeter for http interface testing is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report