Movatterモバイル変換


[0]ホーム

URL:


CN111427765B - Automatically open the interface performance testing method and system based on jmeter implementation - Google Patents

Automatically open the interface performance testing method and system based on jmeter implementation
Download PDF

Info

Publication number
CN111427765B
CN111427765BCN202010097606.7ACN202010097606ACN111427765BCN 111427765 BCN111427765 BCN 111427765BCN 202010097606 ACN202010097606 ACN 202010097606ACN 111427765 BCN111427765 BCN 111427765B
Authority
CN
China
Prior art keywords
interface
test
file
jmeter
program
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010097606.7A
Other languages
Chinese (zh)
Other versions
CN111427765A (en
Inventor
史静慧
王晓杰
杨琪翔
李桢
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Dingdang Fast Medicine Technology Group Co ltd
Original Assignee
Dingdang Fast Medicine Technology Group Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Dingdang Fast Medicine Technology Group Co ltdfiledCriticalDingdang Fast Medicine Technology Group Co ltd
Priority to CN202010097606.7ApriorityCriticalpatent/CN111427765B/en
Publication of CN111427765ApublicationCriticalpatent/CN111427765A/en
Application grantedgrantedCritical
Publication of CN111427765BpublicationCriticalpatent/CN111427765B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Images

Classifications

Landscapes

Abstract

Translated fromChinese

本发明公开了一种自动开启基于jmeter实现的接口性能测试方法,包括以下步骤:利用python unittest工具制作.py接口文件组,所述.py接口文件组中包括接口自动化测试程序和jmeter启动程序;运行.py接口文件组,首先执行接口自动化测试程序,若测试成功,则直接自动运行jmeter启动程序。利用本发明的方法,能够在利用python unittest工具进行接口测试之后,自动开启jmeter接口压力测试,进行快速联动测试,并降低测试人员的编码工作量。本发明还公开了基于该方法的系统,电子设备以及存储介质。

Figure 202010097606

The invention discloses a method for automatically opening an interface performance test based on jmeter implementation, comprising the following steps: using a python unittest tool to create a .py interface file group, wherein the .py interface file group includes an interface automatic test program and a jmeter startup program; Run the .py interface file group, first execute the interface automation test program, if the test is successful, the jmeter startup program will be automatically run directly. By using the method of the present invention, after the interface test is performed by using the python unittest tool, the jmeter interface pressure test can be automatically started, the fast linkage test can be performed, and the coding workload of the tester can be reduced. The invention also discloses a system, an electronic device and a storage medium based on the method.

Figure 202010097606

Description

Translated fromChinese
自动开启基于jmeter实现的接口性能测试方法和系统Automatically open the interface performance testing method and system based on jmeter implementation

技术领域technical field

本发明涉及一种芯片的电源管理方法。更具体地说,本发明涉及一种用于低频RFID电源管理方法。The invention relates to a power management method of a chip. More specifically, the present invention relates to a method for low frequency RFID power management.

背景技术Background technique

众所周知,在软件开发过程中,需要进行性能测试。性能测试是通过性能测试工具模拟多种正常、峰值以及异常负载条件来对系统的各项性能指标进行测试。As we all know, in the software development process, performance testing is required. Performance testing is to test various performance indicators of the system by simulating a variety of normal, peak and abnormal load conditions through performance testing tools.

性能测试通常包括负载测试和压力测试。其中,负载测试是指模拟实际软件系统所承受的负载条件的系统负荷,通过不断加载(如逐渐增加模拟用户的数量)或其它加载方式来观察不同负载下系统的响应时间和数据吞吐量、系统占用的资源(如CPU、内存)等,以检验系统的行为和特性,以发现系统可能存在的性能瓶颈、内存泄漏、不能实时同步等问题。压力测试是指是在强负载(大数据量、大量并发用户等)下的测试,查看应用系统在峰值使用情况下操作行为,从而有效地发现系统的某项功能隐患、系统是否具有良好的容错能力和可恢复能力。压力测试分为高负载下的长时间(如24小时以上)的稳定性压力测试和极限负载情况下导致系统崩溃的破坏性压力测试。(声明:负载测试与压力测试的解释文字来自CSDN博主「go_pig」的原创文章,遵循CC 4.0BY-SA版权协议,原文链接:https://blog.csdn.net/go_pig/article/details/79729059)Performance testing usually includes load testing and stress testing. Among them, the load test refers to the system load that simulates the load conditions of the actual software system, and observes the response time and data throughput of the system under different loads through continuous loading (such as gradually increasing the number of simulated users) or other loading methods. Occupied resources (such as CPU, memory), etc., to check the behavior and characteristics of the system to find possible performance bottlenecks, memory leaks, and inability to synchronize in real time. Stress test refers to a test under a strong load (large data volume, a large number of concurrent users, etc.), to check the operation behavior of the application system under peak usage conditions, so as to effectively discover the hidden dangers of a certain function of the system and whether the system has good fault tolerance. capacity and resilience. The stress test is divided into a long-term stability stress test under high load (such as more than 24 hours) and a destructive stress test that causes the system to collapse under extreme load conditions. (Disclaimer: The explanatory text of the load test and stress test comes from the original article of the CSDN blogger "go_pig", following the CC 4.0BY-SA copyright agreement, the original link: https://blog.csdn.net/go_pig/article/details/ 79729059)

在软件开发过程中,这两种性能测试,都是需要的。本发明主要涉及接口的性能测试,例如登录接口的性能测试。既可以进行性能测试,也可以进行压力测试,但更偏向于接口的压力测试。In the software development process, these two kinds of performance tests are needed. The present invention mainly relates to the performance test of the interface, such as the performance test of the login interface. Both performance testing and stress testing can be performed, but the stress testing of the interface is more preferred.

本发明基于python unittest+jmeter性能测试方法,去监测接口服务器承受压力的健壮性。其中,python unittest为python内置的用于测试代码的模块,jmeter为一款纯java编写的负载测试和压力测试开源工具软件。The invention monitors the robustness of the interface server under pressure based on the python unittest+jmeter performance testing method. Among them, python unittest is a built-in python module for testing code, and jmeter is an open source tool software for load testing and stress testing written in pure java.

本发明测试的内容包括:The contents of the present invention test include:

广义:单位时间内同时发送给服务器的请求数,不限定具体业务类型,强调的是同时发送;In a broad sense: the number of requests sent to the server at the same time per unit of time, not limited to specific business types, emphasizing simultaneous sending;

狭义:是单位时间内同时发送给服务器的相同的业务请求数,需限定具体的业务类型,强调业务请求相同,例如都是登录操作;Narrow definition: It is the same number of business requests sent to the server at the same time per unit time. It is necessary to limit the specific business type, emphasizing that the business requests are the same, such as login operations;

上述的请求数,可以从以下三个方面考量:The above number of requests can be considered from the following three aspects:

服务端视角:并发数为单位时间内服务端接收到的请求数;Server perspective: The number of concurrent requests is the number of requests received by the server in unit time;

客户端视角:客户端的某个具体业务行为包括多个请求,并发数可被理解为客户端单位时间内同时发送给服务器端的请求数;Client perspective: a specific business behavior of the client includes multiple requests, and the number of concurrency can be understood as the number of requests sent by the client to the server at the same time per unit of time;

用户视角:客户端的业务请求一般为用户操作行为,并发数也可理解为并发用户数,又可称为虚拟用户数。User perspective: The client's business request is generally user operation behavior, and the number of concurrent users can also be understood as the number of concurrent users, which can also be called the number of virtual users.

对软件进行性能测试,是为了:Software performance testing is performed to:

获取正常请求流量下,系统的各个性能指标,比如系统反应速度之类的参数,cpu,内存,或磁盘占用情况等。Obtain various performance indicators of the system under normal request traffic, such as parameters such as system response speed, cpu, memory, or disk usage.

获取系统能够承载的极限容量,以及获得系统的性能瓶颈,比如最多支持多少人同时上线或进行类似登录的接口操作等。Obtain the limit capacity that the system can carry, and obtain the performance bottleneck of the system, such as the maximum number of people that can be online at the same time or perform login-like interface operations.

获取系统的健壮性,例如连续开启多长时间容易发生故障等。Get the robustness of the system, such as how long it is prone to failure when it is turned on continuously.

在性能测试时,辅助系统参数调整。In the performance test, the auxiliary system parameters are adjusted.

有助于系统性能回归:在版本升级时,通常需要对比新老版本的性能情况。Contribute to system performance regression: When upgrading a version, it is usually necessary to compare the performance of the new and old versions.

既然软件测试如此重要,当前业界存在多种测试工具,流行常用的性能测试工具有loadrunner,jmeter,和postman。本发明利用jmeter测试工具。Since software testing is so important, there are currently a variety of testing tools in the industry. Popular performance testing tools include loadrunner, jmeter, and postman. The present invention utilizes the jmeter test tool.

但是,在测试的时候,首先需要测试软件是否能正常操作,然后再利用jmeter测试工具进行压力测试或负载测试,这样比较麻烦。例如,如果是测试接口,那么首先要测试当接口接收到请求后,是否能够得到正确的返回值。在确定接口正常之后,再进行jmeter性能测试。However, when testing, you first need to test whether the software can operate normally, and then use the jmeter testing tool to perform stress testing or load testing, which is rather troublesome. For example, if you are testing an interface, you must first test whether the interface can get the correct return value after receiving the request. After confirming that the interface is normal, perform the jmeter performance test.

为提高测试的便利性,需要开发一种新技术,来解决检查错误不便的问题,以及能够尽量规避重复代码,且降低交互失败的概率。In order to improve the convenience of testing, it is necessary to develop a new technology to solve the problem of inconvenient error checking, avoid duplication of code as much as possible, and reduce the probability of interaction failure.

发明内容SUMMARY OF THE INVENTION

本发明的一个目的是至少解决上述问题,并提供后面将说明的其它优点;An object of the present invention is to solve at least the above-mentioned problems, and to provide other advantages which will be described later;

本发明另一个目的是提供一种自动开启基于jmeter实现的接口性能测试方法,能够快速实现接口测试;Another object of the present invention is to provide a method for automatically opening interface performance testing based on jmeter implementation, which can quickly realize interface testing;

本发明的又一个目的是提供一种自动开启基于jmeter实现的接口性能测试方法,能够减少或避免重复代码的开发,提高开发效率;以及Yet another object of the present invention is to provide a method for automatically opening interface performance testing based on jmeter implementation, which can reduce or avoid the development of repetitive codes and improve development efficiency; and

本发明的再一个目的是提供一种自动开启基于jmeter实现的接口性能测试方法,能够在接口测试完成后,自动启动接口的性能测试,以降低测试成本。Another object of the present invention is to provide a method for automatically starting the interface performance test based on jmeter, which can automatically start the interface performance test after the interface test is completed, so as to reduce the test cost.

为了实现根据本发明的这些目的和其它优点,提供了自动开启基于jmeter实现的接口性能测试方法,包括以下步骤:In order to achieve these objects and other advantages according to the present invention, a method for automatically opening an interface performance test based on jmeter implementation is provided, including the following steps:

利用python unittest工具制作.py接口文件组,所述.py接口文件组中包括接口自动化测试程序和jmeter启动程序;Using the python unittest tool to create a .py interface file group, the .py interface file group includes an interface automation test program and a jmeter startup program;

运行.py接口文件组,首先执行接口自动化测试程序,若测试成功,则直接自动运行jmeter启动程序。Run the .py interface file group, first execute the interface automation test program, if the test is successful, the jmeter startup program will be automatically run directly.

这样,在利用python unittest进行接口测试之后,看测试是否成功。若不成功,则程序终止,待接口程序修复之后,重新进行测试。这里虽然将python unittest工具制作.py文件称作接口文件组,实际上除了接口软件,其它软件程序也同样适用。任何软件程序,可以利用python unittest和jmeter进行测试的,均可采用本发明的联合检测方法,均能实现上述发明目的。In this way, after using python unittest for interface testing, see if the test is successful. If unsuccessful, the program is terminated, and the test is performed again after the interface program is repaired. Although the .py file produced by the python unittest tool is called an interface file group, in fact, in addition to the interface software, other software programs are also applicable. Any software program that can be tested by using python unittest and jmeter can adopt the joint detection method of the present invention, and can achieve the above-mentioned purpose of the invention.

所述的自动开启基于jmeter实现的接口性能测试方法中,所述.py接口文件组包括:In the described interface performance testing method based on jmeter implementation, the .py interface file group includes:

Json文件,其中存储有待测试接口的,根据关键词key为识别标识的接口相关数据;Json file, in which the interface to be tested is stored, and the interface-related data of the identification mark is identified according to the keyword key;

Excel文件,其中存储有所述关键词key和待测试接口的接口参数;和Excel file in which the keyword key and interface parameters of the interface to be tested are stored; and

.py接口脚本,其中配置有指定的jmeter性能工具的.jmx文件路径,用于运行jmeter启动程序;.py interface script, which is configured with the .jmx file path of the specified jmeter performance tool, used to run the jmeter startup program;

其中,.py接口脚本从Excel文件中读取待测试接口的关键词key,根据该关键词key,从Json文件中读取相应的接口相关数据,将读取到的接口输入数据拼接到待测试接口的接口参数中形成接口数据,所述待测试的接口调用该接口数据进行接口测试。。Among them, the .py interface script reads the keyword key of the interface to be tested from the Excel file, reads the corresponding interface-related data from the Json file according to the keyword key, and splices the read interface input data to the interface to be tested. Interface data is formed in the interface parameters of the interface, and the interface to be tested calls the interface data to perform interface testing. .

本发明的一套程序,可以对多个接口进行测试。只需要在excel文件中,存储接口识别代码,例如接口中的关键词参数key。通过关键词key,.py接口脚本就能够在Json文件中顺利地找到待检测的接口的相关参数,然后利用找到的相关参数,.py接口脚本就能够对接口进行测试了。测试完成后,在成功的情况下,由于在.py接口脚本中,配置有指定的.jmx文件路径,就可以直接启动jmeter测试程序。Jmeter测试程序主要进行压力测试,但也可以进行其它性能测试。A set of programs of the present invention can test multiple interfaces. It is only necessary to store the interface identification code in the excel file, such as the keyword parameter key in the interface. Through the keyword key, the .py interface script can successfully find the relevant parameters of the interface to be detected in the Json file, and then use the found relevant parameters, the .py interface script can test the interface. After the test is completed, in the case of success, since the specified .jmx file path is configured in the .py interface script, the jmeter test program can be started directly. The Jmeter test program mainly performs stress testing, but can also perform other performance tests.

所述的自动开启基于jmeter实现的接口性能测试方法中,所述进行接口测试包括:In the described method of automatically opening the interface performance testing method based on jmeter implementation, the performing the interface test includes:

.py接口脚本调用接口后,返回Json数据,解析接口返回的Json数据,提取其中的测试结果字段,根据该字段判断测试结构,从而实现接口的自动化测试。After the .py interface script calls the interface, it returns the Json data, parses the Json data returned by the interface, extracts the test result field, and judges the test structure according to the field, so as to realize the automatic test of the interface.

测试接口是否正常可以采用上述方法,即检测Json的返回数据是否正常,若正常,则意味着接口的自动化测试成功。To test whether the interface is normal, the above method can be used, that is, to detect whether the returned data of Json is normal. If it is normal, it means that the automatic test of the interface is successful.

所述的自动开启基于jmeter实现的接口性能测试方法中,所述运行jmeter启动程序包括:In the described method for automatically opening the interface performance test method based on jmeter implementation, the running jmeter startup program includes:

启动jmeter性能工具的.jmx文件,则运行jmeter启动程序,对接口进行jmeter压力测试。Start the .jmx file of the jmeter performance tool, then run the jmeter startup program to perform the jmeter stress test on the interface.

当接口检测成功后,进一步对接口进行压力测试。这时候,由于在.py文件中记载了.jmx文件的路径,因此能够顺利启动该文件。启动.jmx文件后,则运行jmeter启动程序,对接口进行jmeter压力测试。After the interface is successfully detected, further stress test the interface. At this time, since the path of the .jmx file is recorded in the .py file, the file can be started smoothly. After starting the .jmx file, run the jmeter startup program to perform the jmeter stress test on the interface.

所述的自动开启基于jmeter实现的接口性能测试方法中,在jmeter启动程序中,利用的场景组件包括:线程组、http请求取样器、http头部文件、http cookie管理器、集合点、关联、结果视图、和结果分析器。In the described method of automatically opening the interface performance test method based on jmeter implementation, in the jmeter startup program, the scene components utilized include: thread group, http request sampler, http header file, http cookie manager, rendezvous point, association, Results View, and Results Analyzer.

本发明利用上述场景组件,能够更加清晰地利用jmeter完成接口的压力测试。The present invention utilizes the above-mentioned scenario components, and can use jmeter to complete the stress test of the interface more clearly.

本发明还提供一种自动开启基于jmeter实现的接口性能测试系统,包括:The present invention also provides an interface performance testing system that automatically starts based on jmeter implementation, including:

python unittest工具,利用其制作.py接口文件组,所述.py接口文件组中包括接口自动化测试程序和jmeter启动程序,The python unittest tool is used to make a .py interface file group. The .py interface file group includes an interface automation test program and a jmeter startup program.

所述.py接口文件组,首先执行接口自动化测试程序,若测试成功,则直接自动运行jmeter启动程序。In the .py interface file group, the interface automation test program is executed first, and if the test is successful, the jmeter startup program is directly and automatically run.

所述的自动开启基于jmeter实现的接口性能测试系统中,所述.py接口文件组包括:In the described interface performance testing system based on jmeter implementation, the .py interface file group includes:

Json文件,其中存储有待测试接口的,根据关键词key为识别标识的接口相关数据;Json file, in which the interface to be tested is stored, and the interface-related data of the identification mark is identified according to the keyword key;

Excel文件,其中存储有所述关键词key和待测试接口的接口参数;和Excel file in which the keyword key and interface parameters of the interface to be tested are stored; and

.py接口脚本,其中配置有指定的jmeter性能工具的.jmx文件路径,用于运行jmeter启动程序;.py interface script, which is configured with the .jmx file path of the specified jmeter performance tool, used to run the jmeter startup program;

其中,.py接口脚本从Excel文件中读取待测试接口的关键词key,根据该关键词key,从Json文件中读取相应的接口相关数据,将读取到的接口输入数据拼接到待测试接口的接口参数中形成接口数据,所述待测试的接口调用该接口数据进行接口测试。。Among them, the .py interface script reads the keyword key of the interface to be tested from the Excel file, reads the corresponding interface-related data from the Json file according to the keyword key, and splices the read interface input data to the interface to be tested. Interface data is formed in the interface parameters of the interface, and the interface to be tested calls the interface data to perform interface testing. .

所述的自动开启基于jmeter实现的接口性能测试系统中,.py接口脚本调用接口后,返回Json数据,解析接口返回的Json数据,提取其中的测试结果字段,根据该字段判断测试结构,从而实现接口的自动化测试。In the described interface performance test system based on jmeter implementation, the .py interface script returns Json data after calling the interface, parses the Json data returned by the interface, extracts the test result field, and judges the test structure according to the field, so as to realize Automated testing of interfaces.

本发明还公开了一种电子设备,其中,包括:至少一个处理器,以及与所述至少一个处理器通信连接的存储器,其中,所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器执行上述方法中任一项所述的方法。The present invention also discloses an electronic device, comprising: at least one processor, and a memory connected in communication with the at least one processor, wherein the memory stores instructions executable by the at least one processor , the instructions are executed by the at least one processor to cause the at least one processor to perform the method described in any one of the above methods.

本发明还公开了一种存储介质,其上存储有计算机程序,其中,该程序被处理器执行时,实现上述方法中任一项所述的方法。The invention also discloses a storage medium on which a computer program is stored, wherein, when the program is executed by a processor, any one of the methods described above is implemented.

本发明至少包括以下有益效果:1)提高测试效率;2)减少测试人员的代码开发量;3)通过联动测试,提高测试的可靠性。The present invention at least includes the following beneficial effects: 1) improving the test efficiency; 2) reducing the code development amount of the testers; 3) improving the reliability of the test through the linkage test.

本发明的其它优点、目标和特征将部分通过下面的说明体现,部分还将通过对本发明的研究和实践而为本领域的技术人员所理解。Other advantages, objects, and features of the present invention will appear in part from the description that follows, and in part will be appreciated by those skilled in the art from the study and practice of the invention.

附图说明Description of drawings

图1为本发明自动开启基于jmeter实现的接口性能测试方法的流程示意图。FIG. 1 is a schematic flowchart of the present invention to automatically start an interface performance testing method based on jmeter implementation.

具体实施方式Detailed ways

下面结合附图对本发明做进一步的详细说明,以令本领域技术人员参照说明书文字能够据以实施。The present invention will be further described in detail below with reference to the accompanying drawings, so that those skilled in the art can implement it with reference to the description.

应当理解,本文所使用的诸如“具有”、“包含”以及“包括”术语并不配出一个或多个其它元件或其组合的存在或添加。It should be understood that terms such as "having", "comprising" and "including" as used herein do not assign the presence or addition of one or more other elements or combinations thereof.

本发明目的是克服上述现有工具背景技术中不足,提供基于jmeter的性能测试方法,遵循测试框架的基本原则,将业务逻辑测试脚本分离,测试脚本与测试数据分离,可以随时根据需求进行变更,实现数据驱动测试的模式(相同的测试脚本使用不同的测试数据来执行,就叫数据驱动,这样就实现了数据与测试的彻底分离),可较大减低对测试人员编码水平的要求。这样,测试人员只要拿来测试脚本就能使用,不管针对什么数据。The object of the present invention is to overcome the deficiencies in the background technology of the above-mentioned existing tools, provide a performance testing method based on jmeter, follow the basic principles of the test framework, separate the business logic test script, the test script and the test data, and can be changed at any time according to requirements, Implementing the data-driven testing mode (the same test script is executed with different test data is called data-driven, thus realizing the complete separation of data and testing), which can greatly reduce the coding level of testers. In this way, testers can use as long as they bring test scripts, regardless of the data.

如图1所示:本发明提供了一种基于Jmeter性能测试方法,主要是对接口进行压测,采用该方法能够提高测试效率。为了达到目的,本发明的技术方案实现过程,通过python unittest(用python语言编写的联合测试脚本)unittest接口自动化测试框架+jmeter工具,在接口自动化脚本(就是python unittest)执行完毕之后,以命令的方式非人为启动jmeter已搭建好的场景(就是测试场景),如被测接口的.jmx脚本文件(这个脚本文件中就包括后面的jmetet场景中的组件,就是设置这些组件的脚本)。Jmeter场景的组件构成有:线程组、http请求取样器、http头部文件、http cookie管理器、集合点、关联、结果视图、结果分析器。遵循测试框架的基本原则(就是前面讲的分离原则),可以随时根据需求进行变更,对接口调整灵活度高,可较大减低接口的冗余。As shown in FIG. 1 , the present invention provides a Jmeter-based performance testing method, which mainly performs pressure testing on an interface, and the testing efficiency can be improved by adopting this method. In order to achieve the purpose, the implementation process of the technical solution of the present invention, through python unittest (joint test script written in python language) unittest interface automation test framework + jmeter tool, after the interface automation script (that is, python unittest) is executed, the command is The method is non-human to start the scene that jmeter has built (that is, the test scene), such as the .jmx script file of the tested interface (this script file includes the components in the following jmetet scene, which is the script for setting these components). The components of the Jmeter scene are: thread group, http request sampler, http header file, http cookie manager, rendezvous point, association, result view, and result analyzer. Following the basic principles of the test framework (that is, the separation principle mentioned above), changes can be made at any time according to requirements, and the interface adjustment flexibility is high, which can greatly reduce the redundancy of the interface.

图1包括以下步骤:Figure 1 includes the following steps:

A.基于场景分析,需确定比如一个被测的get请求方式的接口,模拟50个用户在N秒内进行抗压测试:A. Based on the scenario analysis, it is necessary to determine the interface of the get request method under test, and simulate 50 users to perform a stress test within N seconds:

B.进行先在jmeter里设置好压测场景脚本以及接口内容,设置模拟真实场景的用户数量,生成响应的输入事件,配置线程组参数。B. First, set the stress test scene script and interface content in jmeter, set the number of users to simulate the real scene, generate the input event of the response, and configure the thread group parameters.

C.接口文件进行配置服务器域名或者ip,端口路由地址,对接口进行参数化,为了方便查看执行结果配置查看结果树用来查看接口返回数据以及接口支付执行通过、聚合报告、图形结果用来衡量被测接口性能指标.C. The interface file is used to configure the server domain name or ip, port routing address, and parameterize the interface. In order to facilitate viewing the execution result, configure the viewing result tree to view the interface return data and the interface payment execution pass, aggregate report, and graph results to measure The performance indicators of the tested interface.

D.python unittest脚本中使用命令的方式调起jmeter,执行.jmx脚本.D. Call up jmeter by using commands in the python unittest script and execute the .jmx script.

例如,代码如下:For example, the code is as follows:

Figure BDA0002385709300000061
Figure BDA0002385709300000061

E.查看接口返回的数据,以及确认接口执行通过情况。E. View the data returned by the interface, and confirm the execution of the interface.

F.聚合报告F. Aggregated Reports

平均响应时间(Average)是我们性能测试的一个重要衡量指标,但是在测试中,特别是在聚合报告中,得出的90%Line,90%响应时间是说在发送的请求中,90%的用户响应时间都比得到的数值上要短,同时说明,一个系统在应用时,90%的用户响应时间都能达到这个数值,那么就为系统性能分析提供了很好的参考价值。但是从不同的视角下,衡量响应时间的指标也各不相同。在实际测试过程中,要明确以什么视角验证被测对象的性能。大多数情况下,我们用jmeter做性能测试的响应时间都以用户视角去看待。The average response time (Average) is an important measure of our performance test, but in the test, especially in the aggregated report, the 90% Line, 90% response time means that in the sent requests, 90% of the The user response time is shorter than the obtained value. At the same time, it shows that when a system is applied, 90% of the user response time can reach this value, which provides a good reference value for system performance analysis. But from different perspectives, the metrics for measuring response time are also different. In the actual testing process, it is necessary to clarify what perspective to verify the performance of the object under test. In most cases, the response time we use jmeter for performance testing is viewed from the user's perspective.

G.图形结果:G. Graphical Results:

1.No of Samples样本数目:总共发送到服务器的请求数1. No of Samples: The total number of requests sent to the server

2.Latest Sample最新样本:服务器相应最后一个请求的时间2.Latest Sample latest sample: the time when the server corresponds to the last request

3.Average平均值:总运行时间除以发送到服务器的请求数3.Average average: total runtime divided by the number of requests sent to the server

4.Deviation偏离:服务器响应时间变化,离散程度测试值的大小,也就是数据的分布4.Deviation deviation: server response time changes, the size of the discrete degree test value, that is, the distribution of data

5.Throughput吞吐量:服务器每分钟处理的请求数5.Throughput throughput: The number of requests processed by the server per minute

6.Median中值:所有请求按大小顺序排列,处于中间位置的数,数值为服务器相应时间6. Median value: all requests are arranged in order of size, the number in the middle position, the value is the corresponding time of the server

H.根据聚合报告和图形结果,若要用jmeter自带的性能测试报告可执行命令:H. According to the aggregated report and graphical results, if you want to use the performance test report that comes with jmeter, you can execute the command:

1.打开cmd命令模式进入Jmeter的bin目录。1. Open the cmd command mode and enter the bin directory of Jmeter.

输入jmeter-n-t E:\Jmeter\apache-jmeter-5.0\bin\addcart-post请求.jmx-lresult.jtl-e-o E:\apache-jmeter-5.0\bin\WebReportEnter jmeter-n-t E:\Jmeter\apache-jmeter-5.0\bin\addcart-post request.jmx-lresult.jtl-e-o E:\apache-jmeter-5.0\bin\WebReport

执行成功后会在Jmeter的bin目录下生成WebReport文件。After successful execution, the WebReport file will be generated in the bin directory of Jmeter.

本发明.py文件的示例代码如下:The example code of the .py file of the present invention is as follows:

Figure BDA0002385709300000071
Figure BDA0002385709300000071

Figure BDA0002385709300000081
Figure BDA0002385709300000081

Figure BDA0002385709300000091
Figure BDA0002385709300000091

本发明的基于python unittest接口自动化测试框架并在该框架中的接口脚本.py中配置指定的jmeter性能.jmx文件路径,python unittest接口自动化测试框架中的.py接口文件从Excel中读取json关键词,根据json关键词(就是key)从json文件中读取接口相关数据,将读取的接口输入数据拼接到接口参数中(接口参数应该是在.py文件中的),调用接口(就是待测试的接口),解析接口返回的JSON数据,提取有用字段(判断接口是否通过测试),从而实现接口自动化测试。当python unittest接口自动化测试框架中的.py文件执行完毕之后,启动jmeter性能工具的.jmx文件进行对接口进行压测。The present invention is based on the python unittest interface automated testing framework and configures the specified jmeter performance.jmx file path in the interface script.py in the framework, and the .py interface file in the python unittest interface automated testing framework reads the json key from Excel word, read the interface-related data from the json file according to the json keyword (that is, the key), splice the read interface input data into the interface parameters (the interface parameters should be in the .py file), and call the interface (that is, to be Tested interface), parse the JSON data returned by the interface, extract useful fields (judging whether the interface passes the test), so as to realize the automatic test of the interface. After the .py file in the python unittest interface automation testing framework is executed, start the .jmx file of the jmeter performance tool to test the interface.

本发明的基于python unittest接口自动化测试框架,创建python项目,建立可执行的python unittest的.py接口文件,用.py接口文件读取Excel中设置与接口名称一致的关键字段与json文件匹配,目的是为了使用关键词读取json文件的内容进行参数化(就是用关键词取代json文件中的某个数据)(json用来存储简单的数据结构的,可以在web中数据交换),根据关键词从json文件中读取接口相关参数,将读取的输入数据拼接到接口参数中,调用接口,并在业务逻辑中解析接口向服务端请求的返回结果(就是返回的json数据),提取有用字段进行断言校验,判断预期结果是否与实际结果一致从而实现接口自动化测试。当python unittest接口自动化测试框架中的.py接口文件执行断言完毕之后,自动启动已在.py接口文件配置好的的指定的jmeter性能.jmx文件路径,会自动启动jmeter对当前接口进行压测。The invention based on the python unittest interface automatic testing framework, creates a python project, establishes an executable python unittest .py interface file, and uses the .py interface file to read the key fields in Excel that are consistent with the interface name and match the json file, The purpose is to use keywords to read the content of the json file for parameterization (that is, to replace a certain data in the json file with keywords) (json is used to store simple data structures, and data can be exchanged in the web), according to the key The word reads the interface-related parameters from the json file, splices the read input data into the interface parameters, calls the interface, and parses the return result (that is, the returned json data) requested by the interface to the server in the business logic, extracting useful The field is asserted to check whether the expected result is consistent with the actual result, so as to realize the automatic test of the interface. When the .py interface file in the python unittest interface automation testing framework completes the assertion, the specified jmeter performance .jmx file path configured in the .py interface file is automatically started, and jmeter is automatically started to perform stress testing on the current interface.

更具体地,本发明的基于python unittest接口自动化测试框架,创建python项目项目分层包括:More specifically, based on the python unittest interface automated testing framework of the present invention, creating a python project project hierarchy includes:

1.Excel文件用来管理执行过哪些场景的测试用还用来建立与json文件的关系(就是key)、接口执行的结果:1. The Excel file is used to manage which scenarios have been executed. It is also used to establish the relationship with the json file (that is, the key) and the result of the interface execution:

例(如:用例名称、jesonkey,接口返回接口、执行结果、执行日期)For example (eg: use case name, jesonkey, interface return interface, execution result, execution date)

2.json文件:(json文件是一种key,value格式文件,用来保存向服务器发出请求接口参数(比如登录用的用户名和密码))2.json file: (json file is a key, value format file, used to save the interface parameters of the request to the server (such as the user name and password for login))

3.公共业务逻辑(就是.py文件中,接口的业务逻辑):(解析Excel,先手动维护Excel中的jsonkey,填写(手动维护就是填写)的值是json文件的key。这样就做作到了参数的对应,关系降低数据的耦合性更容易维护,解析出Excel的行数和列数以,将某行的行数以参数的形式传给.py接口文件所调用的方法中使用,这样就做到接口和参数的匹配;断言:校验接口返回的结果是否与预期结果一致。目的,是在业务逻辑更改时不影响.py接口文件的执行,起到的代码的耦合的作用)3. Public business logic (that is, the business logic of the interface in the .py file): (parse Excel, first manually maintain the jsonkey in Excel, and fill in (manual maintenance is to fill in) the value is the key of the json file. In this way, the parameters are achieved Corresponding, the relationship reduces the coupling of the data and is easier to maintain, parse out the number of rows and columns in Excel, and pass the number of rows in a row as a parameter to the method called by the .py interface file. Matching to the interface and parameters; Assert: Verify that the results returned by the interface are consistent with the expected results. The purpose is to not affect the execution of the .py interface file when the business logic changes, and to couple the code)

4.可执行的python unittest的.py接口文件:在编写.py接口文件请求接口之前,读取Excel的行数并赋值给一个自定义变量(自定义变量:人为设置,用来接收值),同时将这个变量以参数的形式传递给requests请求.然后调用公共业务逻辑中的断言,来校验requests的请求结果是否与预期结果一致,并把执行结果报存到excel中。4. The .py interface file of the executable python unittest: Before writing the .py interface file to request the interface, read the number of rows in Excel and assign it to a custom variable (custom variable: artificially set, used to receive values), At the same time, this variable is passed to the requests request in the form of a parameter. Then the assertion in the public business logic is called to verify whether the request result of the requests is consistent with the expected result, and the execution result is reported to excel.

5.启动接口的性能测试:判断某个python unittest的.py接口文件执行结果状态是否是成功,将自动执行python unittest的.py接口文件中已配置好的jmeter性能脚本文件路径启动.jmx文件,达到程序控制工具实现自动执行性能测试的目的。5. Start the performance test of the interface: to judge whether the execution result status of the .py interface file of a python unittest is successful, it will automatically execute the jmeter performance script file path configured in the .py interface file of python unittest to start the .jmx file, To achieve the purpose of the program control tool to realize the automatic execution of the performance test.

其中,excel文件的作用可以不仅仅用于保存关键字key,还可以是:保存测试用例、用关键字key和json文件做匹配关系、保存接口执行结果(成功、失败、或者是未执行)、和保存接口向服务器请求之后返回的数据等。Among them, the function of the excel file can not only be used to save the keyword key, but also: save the test case, use the keyword key and the json file to match the relationship, save the interface execution result (success, failure, or not executed), And save the data returned after the interface requests the server, etc.

本发明的技术方案至少带来如下有益效果:The technical scheme of the present invention brings at least the following beneficial effects:

通过本发明提供的jmeter性能测试方法,直接采用jmeter的http取样器编写接口脚本,使得代码量大大减少,同时采用.csv文件存取接口参数有效提高了程序的读取速度,图形化界面从根本上解决了编码效率低下的问题,测试人员可以在jmeter工具打开.jmx后追加其他的测试场景,脚本维护相对简单。且最终以自定义方式输出一份简洁明了的测试报告,测试报告中使得测试结果及系统瓶颈定位一目了然有效提高测试效率和开发人员定位缺陷的效率。Through the jmeter performance testing method provided by the present invention, the http sampler of jmeter is directly used to write the interface script, so that the amount of code is greatly reduced, and the reading speed of the program is effectively improved by using the .csv file access interface parameters, and the graphical interface is fundamentally The above solves the problem of low coding efficiency. Testers can add other test scenarios after opening .jmx in the jmeter tool, and script maintenance is relatively simple. And finally output a concise and clear test report in a custom way, the test report makes the test results and system bottleneck location clear at a glance, which effectively improves the test efficiency and the efficiency of developers to locate defects.

换言之,本发明1、采用数据驱动的方式执行测试用例,把业务和接口相对独立,方便测试。2、输出简洁报告,方便结果校验及分析,方便后续集成。In other words, in the present invention 1, the test case is executed in a data-driven manner, and the business and the interface are relatively independent, which is convenient for testing. 2. Output a concise report, which is convenient for result verification and analysis, and facilitates subsequent integration.

尽管本发明的实施方案已公开如上,但其并不仅仅限于说明书和实施方式中所列运用,它完全可以被适用于各种适合本发明的领域,对于熟悉本领域的人员而言,可容易地实现另外的修改,因此在不背离权利要求及等同范围所限定的一般概念下,本发明并不限于特定的细节和这里示出与描述的图例。Although the embodiment of the present invention has been disclosed as above, it is not limited to the application listed in the description and the embodiment, and it can be applied to various fields suitable for the present invention. For those skilled in the art, it can be easily Therefore, the invention is not limited to the specific details and illustrations shown and described herein without departing from the general concept defined by the appended claims and the scope of equivalents.

Claims (8)

1. The method for automatically starting the interface performance test realized based on the jmeter is characterized by comprising the following steps of:
the method comprises the steps that a python unit test tool is used for manufacturing a py interface file set, wherein the py interface file set comprises an interface automation test program and a meter starting program;
executing the interface automatic test program, and directly and automatically running a jmeter starting program if the test is successful;
wherein, the py interface file group comprises:
the Json file stores interface related data of the interface to be tested, wherein the interface related data are identified according to the keyword key;
the Excel file is stored with the keyword key and interface parameters of an interface to be tested; and
jmx file path, configured with a specified meter capability tool, for running meter start-up program;
the py interface script reads a keyword key of an interface to be tested from an Excel file, reads corresponding interface related data from a Json file according to the keyword key, splices the read interface input data to interface parameters of the interface to be tested to form interface data, and the interface to be tested calls the interface data to carry out interface.
2. The method for automatically starting the interface performance test based on the meter implementation as claimed in claim 1, wherein the interface automation test program comprises:
and after the py interface script calls the interface, Json data are returned, the Json data returned by the interface are analyzed, a test result field is extracted, and a test structure is judged according to the field, so that the automatic test of the interface is realized.
3. The method for automatically starting a meter-based implementation of interface performance testing as claimed in claim 1, wherein said meter start-up procedure comprises:
jmx file for the meter performance tool was started, the meter start program was run to perform a meter pressure test on the interface.
4. The method for automatically starting the jmeter-based interface performance test as claimed in claim 1, wherein the scenario component utilized in the jmeter startup procedure includes: thread groups, http request samplers, http header files, http cookie managers, rendezvous points, associations, result views, and result analyzers.
5. Automatically starting an interface performance test system realized based on a jmeter, which is characterized by comprising the following steps:
the python unit test tool is used for manufacturing a py interface file set, the py interface file set comprises an interface automation test program and a meter starting program,
the py interface file group executes an interface automatic test program at first, and directly and automatically runs a jmeter starting program if the test is successful;
wherein, the py interface file group comprises:
the Json file stores interface related data of the interface to be tested, wherein the interface related data are identified according to the keyword key;
the Excel file stores the keyword key and interface parameters of the interface to be tested; and
a py interface script, wherein a jmx file path is configured with a specified meter capability tool for running a meter launcher;
the py interface script reads a keyword key of an interface to be tested from an Excel file, reads corresponding interface related data from a Json file according to the keyword key, splices the read interface input data to interface parameters of the interface to be tested to form interface data, and the interface to be tested calls the interface data to perform interface testing.
6. The system for automatically starting the interface performance test realized based on the jmeter as claimed in claim 5, wherein after the py interface script calls the interface, Json data is returned, the Json data returned by the interface is analyzed, a test result field is extracted, and a test structure is judged according to the field, so that the automatic test of the interface is realized.
7. An electronic device, comprising: at least one processor, and a memory communicatively coupled to the at least one processor, wherein the memory stores instructions executable by the at least one processor to cause the at least one processor to perform the method of any of claims 1-4.
8. Storage medium on which a computer program is stored which, when being executed by a processor, carries out the method of any one of claims 1-4.
CN202010097606.7A2020-02-172020-02-17 Automatically open the interface performance testing method and system based on jmeter implementationActiveCN111427765B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202010097606.7ACN111427765B (en)2020-02-172020-02-17 Automatically open the interface performance testing method and system based on jmeter implementation

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202010097606.7ACN111427765B (en)2020-02-172020-02-17 Automatically open the interface performance testing method and system based on jmeter implementation

Publications (2)

Publication NumberPublication Date
CN111427765A CN111427765A (en)2020-07-17
CN111427765Btrue CN111427765B (en)2022-09-20

Family

ID=71547117

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202010097606.7AActiveCN111427765B (en)2020-02-172020-02-17 Automatically open the interface performance testing method and system based on jmeter implementation

Country Status (1)

CountryLink
CN (1)CN111427765B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN112035303B (en)*2020-09-012021-08-24腾讯科技(深圳)有限公司Data testing method and device, computer and readable storage medium
CN112579446A (en)*2020-12-102021-03-30北京软通智慧城市科技有限公司Interface testing method and device, electronic equipment and storage medium
CN112765004B (en)*2021-01-192024-04-26北京睿企信息科技有限公司Automatic and self-adaptive interface performance test method
CN112799930A (en)*2021-01-292021-05-14华夏城视网络电视股份有限公司Distributed pressure testing method and system
CN112732322A (en)*2021-04-012021-04-30上海钐昆网络科技有限公司Data verification method and device, electronic equipment and computer storage medium
CN114090454B (en)*2021-11-292023-01-24苏州万店掌网络科技有限公司Interface automation test method, device, equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US6038378A (en)*1993-07-292000-03-14Digital Esquipment CorporationMethod and apparatus for testing implementations of software specifications
CN108415832A (en)*2018-02-072018-08-17平安科技(深圳)有限公司Automatic interface testing method, device, equipment and storage medium
CN110427331A (en)*2019-09-032019-11-08四川长虹电器股份有限公司The method for automatically generating performance test script based on interface testing tool

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US6038378A (en)*1993-07-292000-03-14Digital Esquipment CorporationMethod and apparatus for testing implementations of software specifications
CN108415832A (en)*2018-02-072018-08-17平安科技(深圳)有限公司Automatic interface testing method, device, equipment and storage medium
CN110427331A (en)*2019-09-032019-11-08四川长虹电器股份有限公司The method for automatically generating performance test script based on interface testing tool

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
Python+requests+unittest+excel实现接口;我被狗咬了;《https://cloud.tencent.com/developer/article/1510595》;20190923;第1-15页*
接口测试框架-关联excel与json文件获取请求参数;燕鸻;《https://www.cnblogs.com/xiaochao-testing/articles/10560231.html》;20190319;第1-2页*
接口测试框架-数据分离;燕鸻;《https://www.cnblogs.com/xiaochao-testing/articles/10559967.html》;20190319;第1-6页*

Also Published As

Publication numberPublication date
CN111427765A (en)2020-07-17

Similar Documents

PublicationPublication DateTitle
CN111427765B (en) Automatically open the interface performance testing method and system based on jmeter implementation
US10552301B2 (en)Completing functional testing
CN109189684B (en)Python-based automatic interface testing method
CN111832236B (en) A chip regression test method, system, electronic device and storage medium
US11755919B2 (en)Analytics for an automated application testing platform
CN108763076A (en)A kind of Software Automatic Testing Method, device, equipment and medium
CN113238940B (en)Interface test result comparison method, device, equipment and storage medium
WO2018184361A1 (en)Application test method, server, terminal, and storage media
CN107678962A (en)The automated testing method and device of a kind of cli interface
CN117493188A (en) Interface testing methods and devices, electronic equipment and storage media
CN115098401B (en) HTML report verification method, device, electronic device and storage medium
CN107797917B (en)Performance test script generation method and device
CN120123242A (en) Automated testing method, device and electronic equipment
CN118885406A (en) Database cluster abnormality testing method and device
CN114564387A (en)Scene type automatic testing method and system for OpenStack cloud platform
CN118779228A (en) Vehicle OTA platform testing method, device, electronic equipment and storage medium
CN112612665A (en)Testing method, device and equipment of financial intelligent equipment
CN112685316A (en)Code execution path acquisition method and device, computer equipment and storage medium
CN118132419A (en)Method for generating test code, automatic regression test method and device thereof
CN115599683A (en)Automatic testing method, device, equipment and storage medium
CN116955140A (en) SDK testing methods, devices, equipment and storage media
CN118550840B (en)Firmware analysis and verification method, jig, computer equipment and storage medium
CN113190453B (en) User interface testing method, device, server and medium
CN120416086A (en) SSE interface testing method, device, electronic device and storage medium
CamposTowards automated load testing through the user interface

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp