[Use] technology blog Postman Jmeter interface and performance testing

Postman use and performance test interface Jmeter

Author: ZBW

version:v1.0


Phylab in the development process, the interface to generate reports for performance consideration is very important. Although the original Latex interface to generate reports in appearance, but the compiler Latex templates rate has been less than satisfactory. In addition to the previous situation because the students there have been many people at the same time generate reports caused the site to crash. Thus the stage we set out to develop an interface to generate reports based on Markdown templates. After the end of the development, consider how the performance of both interfaces becomes a problem we need to focus.

As the testers for Postman more familiar, we first try to use Postman performance testing, but because of its limited functionality, then we use Jmeter tested concurrent terms. So Here's an overview of the use of these two tools.

Postman

Postman is a powerful API testing tool that can initiate complex http request to the server, which request headers, request body and so can be customized by Cookie simple and clear way. Combined with additional browser plug-ins, Postman can also record the browser request occurs.Thus becoming the scripting is a good helper

installation

Here Postman's Chrome browser App, its biggest advantage is the combination of Postman Interceptor browser plug-ins, no additional configuration to capture a request that the browser is launched. (Postman local applications require additional configuration browser proxy information)

The disadvantage is that this Chrome App has been developed in a state of stagnation, will receive Deprecated warnings at startup. However, due to the functions described herein involve relatively simple, we do not consider this issue.

Download Link: Chrome App , Postman Interceptor

Simple to use

First start the reception state Postman Interceptor, wherein the input frame by a regular expression to filter requests the domain name.

After opening Postman app

On the left is a list of requests initiated through software and record viewer initiated, the right is the detailed information for a single request.

测试的第一步是构造请求,可以在右侧的长条状栏内输入请求指向的API,并指定请求的类型。之后填写下方的请求详细信息。最后点击Send即可发送请求,并在面板下方看到请求的结果。

但这里我们的问题是被测接口需要登陆才能使用,而直接由Postman发起的请求默认是不带有任何额外Cookie的,请求结果是Unauthorized。因此这里的简便方法是在登陆网站后在浏览器端点击生成报告,并通过interceptor获取浏览器发起的请求,此时请求内包含了登陆的Cookie信息。

在浏览器发起请求后,Postman会直接记录下请求的详细信息。由于在浏览器上填好数据后点击生成报告,捕获的请求信息中已经包含了测试接口所需的数据。我们再次尝试发送这一请求,收到了服务器的正确返回。

可以将请求保存到Collection中备用。

使用Postman的Runner功能进行自动测试

Postman提供了Runner功能,可以自动运行Collection中的所有测试。点击界面右上角的Runner打开相应界面。其中在Runs下可以选择需要运行的collection。左侧可查看之前的测试结果。中间部分主要用到的为Iteration,代表测试重复的次数;Delay代表每次重复之间的间隔;Data File部分可以上传相应的数据文件。点击Run便可运行测试。

例如我们测试Markdown生成接口的平均耗时,可设置Iteration为10,运行后可以看到每次请求返回的时间及状态码。

可通过Export Test Result导出结果查看具体的报告。

Jmeter进行并发测试

Postman的一大缺点是其只能串行运行测试,而不能并行测试,从而无法测量服务器的并发性能。因此我们开始考虑使用更复杂的工具Jmeter来测试。Jmeter是由Apache基金会旗下的一款负载测试软件,我们仅仅应用了其中的HTTP请求测试,而实际上该软件还可以用于很多方面。

安装

从这里下载Jmeter二进制文件:Download Apache Jmeter

解压后进入bin文件夹,Windows直接运行jmeter.bat即可,Linux下运行jmeter.sh。注意Jmeter的使用需要JRE支持。

简单的Web接口压力测试

Jmeter是一款模块化的软件,功能非常强大,但使用起来需要像搭积木一样增加自己所需的模块。从上手难度上讲要高于Postman。

Jmeter启动后默认打开了一个空的Test Plan。具体的测试内容需要我们自行添加。Jmeter以多线程的方式并行发起请求,因而我们首先需要添加线程组。

点击新增的线程组,可以配置多线程的具体信息。其中Number of Threads为线程的数量,此处180意味着我们在单次测试中会启动180个线程,在我们的测试情况中会发起180个请求。
Ramp-Up Period为创建以上数量线程的时间,这里设置为60意味着180个线程将在60秒内逐步启动。以上我们模拟的是较为平均的高压力使用情况。假若将此值设置为较小的数字,大量请求将同时发起,可以测试突发的情况。
循环次数代表这一线程组测试的次数。我们仅运行1次。

右键设置好的线程组,添加Http请求。

这里即配置我们发起请求的具体内容,其配置方式和Postman非常类似,照猫画虎即可。

注意这里的请求也是不附带任何Cookie信息的。因此我们还需要添加HTTP Cookie Manager来附带额外的登陆Cookie信息。Cookie的内容可以从Postman的测试中获取,也可以由浏览器F12获取。添加后填入需要的Cookie信息即可。这里我们仅需要laravel_session以使网站识别我们的登陆账户。

除此之外我们还需要添加查看结果的相关组件。在Thread Group下增加View Results Tree可以查看每次请求的结果,增加Aggregate Report可以查看累计运行测试的情况。

在全部配置完成后点击界面上方的绿色三角按钮即可运行测试,可以在上述的两个监听器内查看结果,可以点击扫把状的按钮清空运行结果。(如果不清空结果Aggregate Report将持续记录)

在Aggregate Report的底部可以导出结果为csv文件。

Guess you like

Origin www.cnblogs.com/hardchoice/p/10947275.html