From 0 Jmeter combat interface test

In the previous article we introduced to the interface test documentation and test interfaces example, paper-based Jmeter tool to tell you about how to implement the interface test: including the launching of Http request, bypassing the landing, verify the response. Apache JMeter is an organizational development of Java-based stress test tools. It has a free open source framework flexible, multi-platform support and other advantages. In addition to the stress test outside, JMeter test the interface also has a wide range of applications.

Interface test case example

 

 

 

Organization of test cases

Jmeter green installation, the official website (https://jmeter.apache.org/download_jmeter.cgi) After downloading the installation package extract can be used. Open Jmeter, named test plan, the new thread group in the test plan, write interface request in the thread group, save Jmeter test plan Jmeter script (.jmx file).

Jmeter under a test plan can have multiple thread groups, the next Jmeter thread group can have multiple requests Jmeter

Jmeter Test Plan for manual test cases Suite, Jmeter thread group corresponding to the manual test case TestCase, Jmeter request the corresponding test cases by hand Test Step

The interface test cases, test scripts to write the following outline:

 

 

 

Http request initiated

Http request includes three parts, Jmeter using Sampler-> Http request Http request to initiate

The request line (URL HTTP protocol and request, in writing Http request)

Request header (header information, optional, may be prepared Http request header in the header information manager)

Request body (POST request-information is requested, the GET request parameters programmed in Http request in which the request line)

To add a user successfully, for example, the main write the following information:

Test server information: protocol, server name or IP, server port number

Interface information: interface path and interface methods

Request Interface parameters

 

 

 

Bypassing landing

服务端通常都有认证授权机制,在成功发起接口请求并且获取结果以前是需要绕过登陆的,根据不同的认证授权机制,Jmeter提供了不同的组件支持,本示例是通过Cookie绕过登陆。通过Cookie绕过登陆需要添加HttpCookie管理器,在Cookie管理器中添加相应的Cookie信息,可以通过Chorme工具抓取Cookie信息。

 

 

 

 

 
 

断言响应结果

发起Http请求是为了获取响应结果并进行数据验证,Jmeter提供了多种断言组件(响应断言,Json断言,Beanshell断言),本文基于Json断言实现响应报文的校验。选中Http请求,右键添加JSON Assertion,提取响应报文的内容并判定响应报文和预期的结果是否一致,此处通过验证响应消息为“保存会员成功”来验证请求成功的执行并返回结果。

 

 

 

获取接口测试运营结果

运行Jmeter脚本,通过添加监听器监听测试结果,通常用查看结果树来监听测试结果,详情如下:

 

 

 

 

至此,一个简单的Jmeter脚本就编写完毕,在实际的接口测试实现过程中,还需要考虑参数化,多接口的参数传递,数据库的处理,同学们可以参照官网示例不断学习,后续公众号也会继续讲解~

作  者:Testfan  Kitty

出  处:微信公众号:自动化软件测试平台

版权说明:欢迎转载,但必须注明出处,并在文章页面明显位置给出文章链接

Guess you like

Origin www.cnblogs.com/testfan2019/p/11364085.html