CN112749100A - Method for generating automatic test case based on flow recording - Google Patents

Method for generating automatic test case based on flow recording Download PDF

Info

Publication number
CN112749100A
CN112749100A CN202110365111.2A CN202110365111A CN112749100A CN 112749100 A CN112749100 A CN 112749100A CN 202110365111 A CN202110365111 A CN 202110365111A CN 112749100 A CN112749100 A CN 112749100A
Authority
CN
China
Prior art keywords
data
test case
flow
test
generating
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.)
Pending
Application number
CN202110365111.2A
Other languages
Chinese (zh)
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.)
Sichuan XW Bank Co Ltd
Original Assignee
Sichuan XW Bank 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 Sichuan XW Bank Co Ltd filed Critical Sichuan XW Bank Co Ltd
Priority to CN202110365111.2A priority Critical patent/CN112749100A/en
Publication of CN112749100A publication Critical patent/CN112749100A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention belongs to the technical field of software development and software testing, and discloses a method for generating an automatic test case based on flow recording, which comprises the following steps of 1, recording the flow of a tested system, obtaining the http protocol element of the flow, and storing the analyzed data in a database according to a self-defined format; case model design, namely, carrying out model design on the basis of multiple scenes to establish a model base, playing back the recorded flow stored in the database, matching the recorded custom format data of the http protocol element with a model in the model base to generate a test scene, and storing the test scene as a test case set; and step 3: and generating an automatic test script based on the test case set, reading out each test scene in the case set one by one, calling an automatic generation case function module, and automatically generating the test case script. The invention overcomes the problem of incomplete scene verification, can be repeatedly executed, and saves the authenticity and diversity of interface request data.

Description

Method for generating automatic test case based on flow recording
Technical Field
The invention belongs to the technical field of software development and software testing, and particularly relates to a method for generating an automatic test case based on flow recording.
Background
In the internet industry, it is often desirable to test systems. In general, conventional solutions typically involve a tester performing an analysis based on a test and then performing automated test case writing based on the results of the test analysis.
In actual operation, the processing mode is insufficient for various scenes existing in production and various data requested in production, so that incomplete scene verification is easily caused, and production accidents occur.
Disclosure of Invention
Based on the problems, the invention provides a method for generating an automatic test case based on flow recording, which overcomes the problem of incomplete scene verification of the traditional scheme, ensures the scene diversity of the test case, can repeatedly execute the generated case, and saves the authenticity and diversity of interface request data.
In order to solve the technical problem, the technical scheme adopted by the invention is as follows:
a method for generating an automatic test case based on flow recording comprises the following steps,
recording the flow of a tested system, specifically acquiring http protocol elements of the flow, and storing the analyzed data in a database according to a user-defined format;
case model design, specifically, model design is carried out based on multiple scenes to establish a model base, recording flow stored in the database is played back, recorded custom format data of http protocol elements are matched with models in the model base to generate test scenes, and the test scenes are stored as a test case set;
and step 3: the method comprises the steps of generating an automatic test script based on a test case set, specifically, reading out each test scene in the case set one by one, calling an automatic case generation function module, automatically generating the test case script, and generating random or other preset modes for data which cannot be repeatedly used in recorded http protocol elements, namely data which cannot be repeatedly used in the recorded http protocol elements, in the test case, so as to ensure the uniqueness of multiple operations, wherein other data are kept as recorded data.
In an implementation of the present invention, the step 1 specifically includes the following steps:
step 1.1, monitoring a port of a tested server for data interaction by using a function provided by tcpcopy;
step 1.2, data interaction between a tested server monitored by the tcpcopy and the outside is carried out to complete copying, and then the data is forwarded to a specified flow recording server;
step 1.3, intercepting the flow copied by tcpcopy by using mitproxy on a flow recording server, then analyzing tcp, and analyzing the flow into http protocol flow;
and 1.4, analyzing the http protocol by using a python script to obtain http protocol elements, and storing the analyzed data in a database according to a self-defined format.
Further, in step 1.4, the http protocol element includes a request path of the traffic, a request parameter, and a response return.
In an implementation of the present invention, the step 2 specifically includes the following steps:
step 2.1: performing model design, specifically, performing model design on a user with the highest access frequency based on the ip address; carrying out model design on an interface with the largest access amount request; carrying out model design on the scene with insufficient authority and refused for the access response prompt; carrying out model design on an access response error reporting scene; carrying out model design on the scene with the longest access response time to complete the establishment of a model base;
step 2.2: and (3) replaying the recorded flow stored in the database, matching the recorded user-defined format data of the http protocol element with all models in the model library designed in the step 2.1, screening flow requests meeting matching conditions for storage, then generating a plurality of test scenes, and storing the test scenes as a test case set.
In an implementation of the present invention, the step 3 specifically includes the following steps:
step 3.1: reading the test case set information generated in the step 2.2, and reading out each test scene in the case set one by one;
step 3.2: reading flow request data contained in a test scene, reading various http protocol elements of the request data one by one, and then automatically generating a test case script by calling an automatic generation case function module;
step 3.3: and 3.2, generating the test case script automatically generated in the step 3.2 in a random or other preset mode according to the data which cannot be repeatedly used in the recorded http protocol element, so as to ensure the uniqueness of multiple operations, and keeping other data as the recorded data.
Further, in step 3.2, the http protocol element includes a request path, a request parameter, and a response is returned, and the data that cannot be used repeatedly in the recording element in step 3.3 includes a request header, a request path, and a request parameter.
Furthermore, for an interface with a credit authorization verification requirement in the test case, a pre-step, specifically, credit authorization acquisition, may be added.
Compared with the prior art, the invention has the following beneficial effects:
1. the invention generates a plurality of test scenes by matching the recorded flow requests of the tested system through the model, thereby ensuring the diversity of the scenes of the test cases.
2. The invention generates data which can not be repeatedly used in recording elements such as a request head, a request path, a request parameter and the like in a random way and the like, thereby ensuring that the data which is repeatedly operated has uniqueness; and replacing other data with recorded data, and then calling the automatic case generation function module to generate an automatic test case, wherein the generated case can be repeatedly executed for multiple times after the data processing, and the authenticity and diversity of the interface request data are also saved.
Detailed Description
The present invention will be further described with reference to the following examples, which are intended to illustrate only some, but not all, of the embodiments of the present invention. Based on the embodiments of the present invention, other embodiments used by those skilled in the art without any creative effort belong to the protection scope of the present invention.
In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the embodiments will be briefly described below. It is obvious that the following description is only some examples or embodiments of the present description, and it will be apparent to those skilled in the art that the present description can be applied to other similar scenarios without inventive effort.
A method for generating an automated test case based on traffic recording.
The scheme comprises the following main steps:
step 1: and recording the flow of the tested system.
Step 1.1: and monitoring a port for data interaction of the tested server by using the function provided by the tcpcopy.
Step 1.2: and (3) performing data interaction between the tested server monitored by the tcpcopy and the outside to complete copying, and then forwarding the data to a specified flow recording server.
Step 1.3: and intercepting the flow copied by the tcpcopy by using the mitproxy on the flow recording server, and then analyzing the tcp to analyze the flow into http protocol flow.
Step 1.4: analyzing the http protocol by using a python script to obtain various http protocol elements such as a request path of flow, a request parameter, a response return and the like, and storing the analyzed data in a database according to a self-defined format.
Step 2: and (5) case model design.
Step 2.1: carrying out model design: specifically, model design is carried out on a user with the highest access frequency based on an ip address; carrying out model design on an interface with the largest access amount request; carrying out model design on the scene with insufficient authority and refused for the access response prompt; carrying out model design on an access response error reporting scene; and performing model design and modeling of other various scenes on the scene with the longest access response time so as to establish a model library.
Step 2.2: and (3) replaying the recorded flow stored in the database, matching the recorded user-defined format data of the http protocol element with all models in the model library designed in the step 2.1, screening flow requests meeting matching conditions for storage, then generating a plurality of test scenes, and storing the test scenes as a test case set.
And step 3: an automated test script is generated based on the set of test cases.
The steps can be as follows:
step 3.1: and (3) reading the test case set information generated in the step (2.2), and reading out each test scene in the case set one by one.
Step 3.2: reading out flow request data contained in a test scene, reading out various http protocol elements such as request paths, request parameters and response returns contained in the request data one by one, and then automatically generating a test case script by calling an automatic generation case function module.
Step 3.3: and 3.2, for the test case script automatically generated in the step 3.2, data which cannot be repeatedly used in the recording elements such as the request head, the request path, the request parameters and the like are generated randomly or in other preset modes such as serialization, the uniqueness is ensured during multiple operation, and other data are kept as the recorded data, so that the generated automatic test case can be repeatedly executed, and the diversity and the authenticity of the data are ensured to the maximum extent.
Step 3.4: and adding a preposed step to an interface with a credit authorization verification requirement in the test case, specifically performing credit authorization acquisition.
Having thus described the basic concept, it will be apparent to those skilled in the art that the foregoing detailed disclosure is to be regarded as illustrative only and not as limiting the present specification. Various modifications, improvements and adaptations to the present description may occur to those skilled in the art, although not explicitly described herein. Such modifications, improvements and adaptations are proposed in the present specification and thus fall within the spirit and scope of the exemplary embodiments of the present specification.
Also, the description uses specific words to describe embodiments of the description. Reference throughout this specification to "one embodiment," "an embodiment," and/or "some embodiments" means that a particular feature, structure, or characteristic described in connection with at least one embodiment of the specification is included. Therefore, it is emphasized and should be appreciated that two or more references to "an embodiment" or "one embodiment" or "an alternative embodiment" in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, some features, structures, or characteristics of one or more embodiments of the specification may be combined as appropriate.
Additionally, the order in which the elements and sequences of the process are recited in the specification, the use of alphanumeric characters, or other designations, is not intended to limit the order in which the processes and methods of the specification occur, unless otherwise specified in the claims. While various presently contemplated embodiments of the invention have been discussed in the foregoing disclosure by way of example, it is to be understood that such detail is solely for that purpose and that the appended claims are not limited to the disclosed embodiments, but, on the contrary, are intended to cover all modifications and equivalent arrangements that are within the spirit and scope of the embodiments herein. For example, although the system components described above may be implemented by hardware devices, they may also be implemented by software-only solutions, such as installing the described system on an existing server or mobile device.
Similarly, it should be noted that in the foregoing description of embodiments of the present specification, various features are sometimes grouped together in a single embodiment or description thereof for the purpose of streamlining the disclosure aiding in the understanding of one or more embodiments of the invention. This method of disclosure, however, is not intended to imply that more features than are expressly recited in a claim. Indeed, the embodiments may be characterized as having less than all of the features of a single embodiment disclosed above.
Finally, it should be understood that the embodiments described herein are merely illustrative of the principles of the embodiments of the present disclosure. Other variations are also possible within the scope of the present description. Thus, by way of example, and not limitation, alternative configurations of the embodiments of the specification can be considered consistent with the teachings of the specification. Accordingly, the embodiments of the present description are not limited to only those embodiments explicitly described and depicted herein.

Claims (7)

1. A method for generating an automatic test case based on flow recording is characterized by comprising the following steps,
recording the flow of a tested system, specifically acquiring http protocol elements of the flow, and storing the analyzed data in a database according to a user-defined format;
case model design, specifically, model design is carried out based on multiple scenes to establish a model base, recording flow stored in the database is played back, recorded custom format data of http protocol elements are matched with models in the model base to generate test scenes, and the test scenes are stored as a test case set;
and step 3: the method comprises the steps of generating an automatic test script based on a test case set, specifically, reading out each test scene in the case set one by one, calling an automatic case generation function module, automatically generating the test case script, randomly generating data which cannot be repeatedly used in a recorded http protocol element in a test case, and ensuring the uniqueness of multiple operations, wherein other data are kept as recorded data.
2. The method for generating an automated test case based on traffic recording according to claim 1, wherein the step 1 specifically comprises the following steps:
step 1.1, monitoring a port of a tested server for data interaction by using a function provided by tcpcopy;
step 1.2, data interaction between a tested server monitored by the tcpcopy and the outside is carried out to complete copying, and then the data is forwarded to a specified flow recording server;
step 1.3, intercepting the flow copied by tcpcopy by using mitproxy on a flow recording server, then analyzing tcp, and analyzing the flow into http protocol flow;
and 1.4, analyzing the http protocol by using a python script to obtain http protocol elements, and storing the analyzed data in a database according to a self-defined format.
3. The method for generating the automated test case based on the traffic record as claimed in claim 2, wherein in step 1.4, the http protocol element includes the request path of the traffic, the request parameter, and the response return.
4. The method for generating an automated test case based on traffic recording according to claim 1, wherein the step 2 specifically comprises the following steps:
step 2.1: performing model design, specifically, performing model design on a user with the highest access frequency based on the ip address; carrying out model design on an interface with the largest access amount request; carrying out model design on the scene with insufficient authority and refused for the access response prompt; carrying out model design on an access response error reporting scene; carrying out model design on the scene with the longest access response time to complete the establishment of a model base;
step 2.2: and (3) replaying the recorded flow stored in the database, matching the recorded user-defined format data of the http protocol element with all models in the model library designed in the step 2.1, screening flow requests meeting matching conditions for storage, then generating a plurality of test scenes, and storing the test scenes as a test case set.
5. The method for generating an automated test case based on traffic recording according to claim 4, wherein the step 3 specifically comprises the following steps:
step 3.1: reading the test case set information generated in the step 2.2, and reading out each test scene in the case set one by one;
step 3.2: reading flow request data contained in a test scene, reading various http protocol elements of the request data one by one, and then automatically generating a test case script by calling an automatic generation case function module;
step 3.3: and 3.2, randomly generating the test case script automatically generated in the step 3.2 according to the data which cannot be repeatedly used in the recorded http protocol element, so as to ensure the uniqueness of repeated operation, and keeping other data as the recorded data.
6. The method for generating an automated test case based on traffic recording as claimed in claim 5, wherein the http protocol element in step 3.2 comprises a request path and a request parameter, and the data that cannot be used repeatedly in the recording element in step 3.3 comprises a request header, a request path and a request parameter in response to the response return.
7. The method for generating an automated test case based on traffic recording as claimed in claim 5, wherein a pre-step is added to an interface having a trust verification requirement in the test case, specifically, a trust acquisition is performed.
CN202110365111.2A 2021-04-06 2021-04-06 Method for generating automatic test case based on flow recording Pending CN112749100A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110365111.2A CN112749100A (en) 2021-04-06 2021-04-06 Method for generating automatic test case based on flow recording

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110365111.2A CN112749100A (en) 2021-04-06 2021-04-06 Method for generating automatic test case based on flow recording

Publications (1)

Publication Number Publication Date
CN112749100A true CN112749100A (en) 2021-05-04

Family

ID=75651720

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110365111.2A Pending CN112749100A (en) 2021-04-06 2021-04-06 Method for generating automatic test case based on flow recording

Country Status (1)

Country Link
CN (1) CN112749100A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115134261A (en) * 2022-06-27 2022-09-30 平安银行股份有限公司 Testing method and device based on flow playback
CN116028376A (en) * 2023-03-27 2023-04-28 云筑信息科技(成都)有限公司 Method for rapidly generating interface automation use cases based on flow recording

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180204150A1 (en) * 2017-01-18 2018-07-19 Wipro Limited System and method for generation of integrated test scenarios
CN108319547A (en) * 2017-01-17 2018-07-24 阿里巴巴集团控股有限公司 Method for generating test case, device and system
CN111797022A (en) * 2020-07-06 2020-10-20 北京嘀嘀无限科技发展有限公司 Test case generation method and device for order splitting service, electronic equipment and medium
CN112100052A (en) * 2020-08-07 2020-12-18 北京奇艺世纪科技有限公司 Interface test scene playback method and device
CN112231232A (en) * 2020-11-18 2021-01-15 深圳前海微众银行股份有限公司 Method, device and equipment for determining test data model and generating test data

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108319547A (en) * 2017-01-17 2018-07-24 阿里巴巴集团控股有限公司 Method for generating test case, device and system
US20180204150A1 (en) * 2017-01-18 2018-07-19 Wipro Limited System and method for generation of integrated test scenarios
CN111797022A (en) * 2020-07-06 2020-10-20 北京嘀嘀无限科技发展有限公司 Test case generation method and device for order splitting service, electronic equipment and medium
CN112100052A (en) * 2020-08-07 2020-12-18 北京奇艺世纪科技有限公司 Interface test scene playback method and device
CN112231232A (en) * 2020-11-18 2021-01-15 深圳前海微众银行股份有限公司 Method, device and equipment for determining test data model and generating test data

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
全栈测试开发日记: "使用Postman工具做接口测试(五)——生成随机参数", 《HTTPS://BLOG.CSDN.NET/LIUDINGLONG1989/ARTICLE/DETAILS/108092039》 *
尹建月 等: "基于UML活动图的测试用例生成方法设计", 《信息化研究》 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115134261A (en) * 2022-06-27 2022-09-30 平安银行股份有限公司 Testing method and device based on flow playback
CN115134261B (en) * 2022-06-27 2023-08-22 平安银行股份有限公司 Flow playback-based testing method and device
CN116028376A (en) * 2023-03-27 2023-04-28 云筑信息科技(成都)有限公司 Method for rapidly generating interface automation use cases based on flow recording
CN116028376B (en) * 2023-03-27 2023-08-29 云筑信息科技(成都)有限公司 Method for rapidly generating interface automation use cases based on flow recording

Similar Documents

Publication Publication Date Title
CN107122296B (en) Method and apparatus for data assertion for test interface
CN107122297B (en) Method and equipment for generating request message of test interface
CN112749100A (en) Method for generating automatic test case based on flow recording
CN107122258B (en) Method and equipment for checking state code of test interface
CN106254153B (en) Network anomaly monitoring method and device
CN107092535B (en) Method and apparatus for data storage of test interface
CN108632213A (en) Facility information processing method and processing device
CN114531304B (en) Session processing method and system based on data packet
CN117155832B (en) Multi-terminal non-invasive recording playback test method and system for UDP transmission protocol
CN113961940A (en) Override detection method and device based on authority dynamic update mechanism
CN107277146B (en) Distributed storage service flow model generation method and system
CN112637005B (en) Flow playback method and device, computer equipment and storage medium
CN111400171B (en) Interface testing method, system and device and readable storage medium
CN113114794A (en) Method and device for processing domain name based on secondary proxy
CN115834443A (en) Flow playback method and device, computer equipment and storage medium
CN112433936A (en) Test method, test device and storage medium
CN114860619B (en) Database audit program regression testing method and device
CN116841645A (en) Database flow processing method and system for database audit
CN115391224A (en) Flow playback method and device, computer equipment and readable storage medium
CN112256595B (en) Heterogeneous system testing method and device and electronic equipment
CN112765045A (en) Case template-based flow playback method
CN115061924A (en) Automatic test case generation method and generation device
CN112468356B (en) Router interface testing method, device, electronic equipment and storage medium
CN111163284B (en) Method, device and equipment for configuring recording and broadcasting host
CN113032255A (en) Response noise recognition method, model, electronic device, and computer storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20210504

RJ01 Rejection of invention patent application after publication