Test case generation method, system, electronic device and storage medium

By generating mirror request packets in interface automation testing and using the processing process of the mirror server to automatically generate test cases, the problem of large labor investment is solved and fast and low-cost test case generation is achieved.

CN114385486BActive Publication Date: 2025-09-02HANGZHOU QULIAN TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111539359.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-15
Publication Date
2025-09-02
Estimated Expiration
2041-12-15

AI Technical Summary

Technical Problem

In the prior art, the generation of interface automation test cases requires a large manpower investment, resulting in a long construction cycle and high maintenance costs.

Method used

By obtaining the request message from the server, generating the mirror request message and sending it to the mirror server, using the processing process of the mirror server, obtaining the response message and automatically generating test cases based on the request and response data.

Benefits of technology

It realizes automated test case generation without human investment, reduces labor costs, shortens construction cycles, and reduces maintenance workload.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114385486B_ABST
    Figure CN114385486B_ABST
Patent Text Reader

Abstract

The present application relates to a test case generation method, system, electronic device and storage medium, which are applied to the field of computer testing technology, wherein the method includes: obtaining a request message sent by a server, wherein the request message carries request data; generating a mirror request message corresponding to the request message, wherein the mirror request message carries request data; sending the mirror request message to the mirror server, wherein the mirror server and the server have the same processing process; obtaining a response message fed back by the mirror server based on the mirror request message, wherein the response message carries response data; generating a test case based on the request data and the response data. This is to solve the problem in the prior art that use case data is generated by manpower, the workload of handwriting interface test cases is large, the forming cycle of interface automation test construction is long, and the maintenance cost of interface test cases is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer testing technology, and in particular to a test case generation method, system, electronic device and storage medium. Background Art

[0002] Interface testing is a type of testing that tests the interfaces between system components. It is primarily used to test the interfaces between the system and other external systems, as well as the interfaces between various sub-modules within the system. The focus of the test is to verify the correctness of interface parameter transmission, the correctness of interface function implementation, the correctness of output results, and the integrity and rationality of fault-tolerant handling of various abnormal situations.

[0003] In related technologies, HTTP interface automated test cases mainly adopt a data-driven approach, separating the use case data and execution logic. The use case data is stored in a medium or file (such as Excel, CSV, etc.) or a database (such as MySQL). Testers can adapt to changes or changes in the business interface to a certain extent without changing or slightly changing the automated test code through maintenance actions such as adding, deleting, modifying, and checking these storage media.

[0004] However, the testing method provided in the relevant technology requires dedicated manpower to generate use case data. The workload of handwriting interface test cases is large, which makes the formation cycle of interface automation testing construction longer and the maintenance cost of interface test cases higher. Summary of the Invention

[0005] The present application provides a test case generation method, system, electronic device and storage medium to solve the problems in the prior art of generating use case data by manpower, the large workload of handwriting interface test cases, the long formation cycle of interface automation test construction, and the high maintenance cost of interface test cases.

[0006] In a first aspect, an embodiment of the present application provides a test case generation method, comprising:

[0007] Obtaining a request message sent by the server, wherein the request message carries request data;

[0008] generating a mirror request message corresponding to the request message, wherein the mirror request message carries the request data;

[0009] Sending the mirroring request message to the mirroring server, the mirroring server and the server process are the same;

[0010] Obtaining a response message fed back by the mirroring server based on the mirroring request message, wherein the response message carries response data;

[0011] Generate a test case based on the request data and the response data.

[0012] Optionally, the generating a mirror request message corresponding to the request message includes:

[0013] Parsing the request message to obtain the request data;

[0014] The mirroring request message is generated according to the request data.

[0015] Optionally, after parsing the request message to obtain the request data, the method further includes:

[0016] storing the request data;

[0017] Generating the mirror request message according to the request data includes:

[0018] Extracting target request data from the stored request data at intervals of a preset duration, wherein the target request data is any request data in the stored request data;

[0019] The mirroring request message is generated according to the target request data.

[0020] Optionally, there is at least one mirroring server, and sending the mirroring request message to the mirroring server includes:

[0021] The mirroring request message is sent to a target mirroring server, where the target mirroring server is a mirroring server that has not responded to the mirroring request message.

[0022] Optionally, generating a test case according to the request data and the response data includes:

[0023] The request data and the response data are concatenated to obtain the test case.

[0024] Optionally, after generating a test case according to the request data and the response data, the method further includes:

[0025] The test case is stored.

[0026] Optionally, the request data includes a request method, a request body, and a request network address, and the response data includes a status code and a response body.

[0027] In a second aspect, an embodiment of the present application provides a test case generation system, comprising: a server, a use case generation end, and a mirror service end;

[0028] The server is used to send the request message sent by the client to the use case generation end;

[0029] The use case generation end is used to obtain a request message sent by the server, wherein the request message carries request data; generate a mirror request message corresponding to the request message, wherein the mirror request message carries the request data; and send the mirror request message to the mirror server, wherein the mirror server performs the same processing as the server;

[0030] The mirroring server is configured to process the mirroring request message to obtain a response message, and send the response message to the mirroring server, wherein the response message carries response data;

[0031] The use case generating end is further configured to obtain a response message fed back by the mirroring service end based on the mirroring request message; and generate a test case according to the request data and the response data.

[0032] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;

[0033] The memory is used to store computer programs;

[0034] The processor is used to execute the program stored in the memory to implement the test case generation method described in the first aspect.

[0035] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the test case generation method described in the first aspect.

[0036] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application obtains a request message sent by the server, the request message carries request data; generates a mirror request message corresponding to the request message, the mirror request message carries request data; sends the mirror request message to the mirror server, and the mirror server and the server have the same processing process; obtains a response message based on the mirror request message feedback from the mirror server, the response message carries response data; generates a test case based on the request data and the response data. In this way, after obtaining the request message, the mirror request message corresponding to the request message is sent to the mirror server, and the mirror server responds to the mirror request message. Then, based on the request data and the response data in the response message sent by the mirror server, a test case is generated. By generating a mirror request message for the request message and completing the response at the mirror server, it will not affect the normal processing of the server, and the test case is automatically generated without manpower, which greatly reduces labor costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0039] Figure 1 A flow chart of a test case generation method provided in one embodiment of the present application;

[0040] Figure 2 A flow chart of a test case generation method provided in another embodiment of the present application;

[0041] Figure 3 A structural diagram of a test case generation system provided in one embodiment of the present application;

[0042] Figure 4 A structural diagram of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0043] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0044] Before further describing the embodiments of the present invention in detail, the nouns and terms involved in the embodiments of the present invention are explained. The nouns and terms involved in the embodiments of the present invention are subject to the following explanations.

[0045] Test case: A test case is a set of test inputs, execution conditions, and expected results compiled for a specific purpose in order to test a program path or verify whether a specific requirement is met.

[0046] Mirroring: It is a form of file storage and a type of redundancy. The data on one disk has an identical copy on another disk, which is called a mirror.

[0047] URL (Uniform Resource Locator), on the WWW, every information resource has a unified and unique address on the Internet. This address is called URL, which is the Uniform Resource Locator of the WWW, that is, the network address.

[0048] DB (data base) is a collection of data organized according to a certain data model and stored in secondary storage.

[0049] In one embodiment of the present application, a test case generation method is provided, which can be applied to any form of electronic equipment, such as a terminal and a server. Figure 1 As shown, the test case generation method includes:

[0050] Step 101: Obtain a request message sent by a server, where the request message carries request data.

[0051] In some embodiments, the server is used to provide actual services to users. After the user fills in the parameter configuration information on the web page, the client sends a request message to the server, the server performs the corresponding processing, and returns the result response message to the web browser, and the normal business process ends.

[0052] Specifically, the obtained request message may be obtained by the server side copying the obtained request message and sending the copied request message to the test case generation end, so that the test case generation end obtains the request message.

[0053] The request data may include, but is not limited to, a request method, a request body, and a request network address.

[0054] The parameter configuration information may be information related to the user request. For example, when the user requests to create a consortium chain, the parameter configuration information may be the name of the consortium chain.

[0055] Step 102: Generate a mirror request message corresponding to the request message, where the mirror request message carries request data.

[0056] In some embodiments, after receiving a request message sent by a server, the request message is saved and a mirror request message corresponding to the request message is generated. By saving the request message, after the server sends multiple request messages, the mirror server can avoid processing multiple mirror request messages, resulting in mismatched requests and responses.

[0057] It is understandable that after the test case generation end obtains the request message, the request message may be directly forwarded to the mirror service end as a mirror request message.

[0058] In an optional embodiment, generating a mirror request message corresponding to the request message includes:

[0059] Parse the request message to obtain request data; and generate a mirror request message based on the request data.

[0060] Specifically, request messages typically exist in the form of signals. Therefore, the request message is parsed to obtain the request data within it, which is then saved. A mirrored request message is then generated based on the request data. When there are multiple request messages, to facilitate processing of each request message and avoid having to process multiple request messages simultaneously on a single mirrored server, the request data is saved first. Once the mirrored server completes processing of the response, the next mirrored request message is processed.

[0061] Furthermore, a mirror request message is generated according to the request data, including:

[0062] At each preset time interval, target request data is extracted from the stored request data, where the target request data is any request data in the stored request data; and a mirror request message is generated according to the target request data.

[0063] In some embodiments, after parsing the request data, the request data is saved. This prevents newly acquired request messages from being missed while the mirroring server is responding to a mirroring request message. Furthermore, after the mirroring server completes processing and returns a response message, the mirroring server extracts the unprocessed target request data from the test case generator and generates a mirroring request message based on the target request data.

[0064] It is understandable that after the mirror request message generated by the request data is sent to the mirror server, the request data of the generated mirror request message can also be marked to determine that the request data has been processed through the mark, thereby avoiding repeated calls to the request data.

[0065] The requested data may be stored in a database of the mirror server. There are many types of databases, for example, but not limited to, a DB database.

[0066] Step 103: Send the mirroring request message to the mirroring server. The processing process of the mirroring server is the same as that of the server.

[0067] In some embodiments, after generating a mirror request message, the mirror request message is sent to a mirror server, which processes the mirror request message to obtain response data, and sends the response data to the test case generation end in the form of a response message.

[0068] Because the mirrored server and the server process are identical, and the mirrored request message carries the same request data as the request message, the resulting response message also contains the same response data. By setting up a mirrored server, performing a secondary simulated request does not interfere with the server actually executing the service.

[0069] In an optional embodiment, there is at least one mirroring server, and sending the mirroring request message to the mirroring server includes:

[0070] The mirror request message is sent to the target mirror server, where the target mirror server is the mirror server that has not responded to the mirror request message.

[0071] By setting up multiple mirror servers, multiple mirror servers can process requests in parallel, which speeds up the mirror processing efficiency of the request message. In addition, each mirror server will respond to the next mirror request message after responding to the previous mirror request message. This ensures a one-to-one correspondence between the mirror request message and the response message.

[0072] Step 104: Obtain a response message fed back by the mirroring server based on the mirroring request message, wherein the response message carries response data.

[0073] In some embodiments, after the mirroring service end obtains the mirroring request message, it processes the mirroring request message to obtain a response message, and sends the response message to the test case generation end, which then obtains the response message.

[0074] Step 105: Generate a test case based on the request data and response data.

[0075] In some embodiments, after obtaining the response message, the test case generation end parses the response message to obtain corresponding data in the response message, thereby generating a test case based on the request data and the response data.

[0076] Among them, since the mirror service end processes one mirror request message each time, obtains a response message and sends it to the test case generation end, and then processes the next mirror request message, the response data in the response message is a response to the request data in the mirror request message, and the two are in a corresponding relationship. Therefore, the test case generated based on the request data and response data is a test case generated for the same request message.

[0077] There are many ways to generate test cases based on request data and response data. For example, the request data and response data may be concatenated to obtain a test case.

[0078] In a specific embodiment, the test case generation method in the embodiment of the present application takes the creation of a consortium chain on a baas platform as an example, assuming that the platform supports the creation of 5 different types of consortium chains (A1-A5 respectively); see Figure 2 , the method may include:

[0079] First, "User A1" creates an "A1 type" consortium chain named "A1 test chain" in the "A1 use case data source environment" (hereinafter referred to as "A1 environment"). First, User A1 writes the parameter configuration information on the web page and confirms the creation. The backend service (i.e., the server) sends a creation request HTTP message. The key message information is as follows: the request method is "post", the request URL is: http: / / xxxx / service / api / v1.0 / create-chain, and the request body is: JSON format data {"ChainInfo":{"ChainName":"A1 test chain","ChainType":"A1"}};

[0080] Second, after receiving the HTTP request (i.e., request message) from the browser (i.e., client), the backend service in the A1 environment performs the corresponding processing and returns a result response message to the browser, thus completing the normal business process. Upon receiving the request from the browser, the backend service also copies the request and forwards it to the collector of the "Use Case Data Automatic Generation Service."

[0081] Third, after receiving the http request, the collector parses the request message to extract "post", "http: / / xxxx / service / api / v1.0 / create-chain", "{"ChainInfo":{"ChainName":"A1 test chain","ChainType":"A1"}}" and other information, and stores the information in the DB database;

[0082] Fourth, the replay device of the "Use Case Data Automatic Generation Service" periodically retrieves information from the DB database, splices it into an HTTP request, and replays the request in a dedicated "secondary simulation request environment". The extracted response message contains the status code: 200 and the response body: {"code":200,"message":"Success","data":{"code":200,"action":"createchain","message":""}};

[0083] Fifth, the processing results of the http request message and response message are spliced ​​into the library to form a test case.

[0084] Among them, after class users A2-A5 create corresponding types of chains in the corresponding environment, they finally form interface test cases for the creation of 5 types of alliance chains from A1 to A5. The use case data is as follows

[0085] Table 1:

[0086]

[0087]

[0088] Table 1

[0089] The test case generation method provided by the embodiment of the present application parses the HTTP request message to extract the request body (including method, URL, version), header, and request body, and temporarily stores the parsed results; simulates the request twice to solve the stateless problem of the HTTP protocol and make the response message correspond to the request message; parses the response message to extract the status line and response body; extracts the response body structure, such as nested JSON returns, and extracts each layer of key for testing and inspection. The HTTP request message and response message processing results are combined into a library to form a test case baseline library. In this way, the interface automation test case baseline is automatically generated and maintenance-free; there are no special requirements for interface development documents, and zero interface documentation can be used to effectively reduce the team burden and quickly build. The initiator of the HTTP request (the source of the use case data) can be a tester, or a developer, product user, or user, effectively shortening the automation test case creation cycle; the adaptability is strong, and the same type of product line and business line can be switched with almost no modification and can be directly applied, significantly shortening the automation construction cycle; the automation access timing is not restricted, and the interface changes caused by business changes are automatically adapted, making it worry-free to use.

[0090] Based on the same concept, a test case generation system is provided in the embodiment of the present application. The specific implementation of the system can be found in the description of the method embodiment part, and the repeated parts will not be repeated. Figure 3 As shown, the system mainly includes: a server 301, a use case generation terminal 302 and a mirroring server 303; wherein:

[0091] The server is used to send the request message sent by the client to the use case generation end;

[0092] The use case generator is used to obtain the request message sent by the server, which carries the request data; generate a mirror request message corresponding to the request message, which carries the request data; and send the mirror request message to the mirror server. The mirror server and the server have the same processing process.

[0093] The mirror server is used to process the mirror request message, obtain a response message, and send the response message to the mirror server. The response message carries response data.

[0094] The use case generation end is also used to obtain the response message fed back by the mirroring server based on the mirroring request message; and generate test cases based on the request data and response data.

[0095] Based on the same concept, an electronic device is also provided in the embodiment of the present application, such as Figure 4 As shown, the electronic device mainly includes: a processor 401, a memory 402 and a communication bus 403, wherein the processor 401 and the memory 402 communicate with each other via the communication bus 403. The memory 402 stores a program that can be executed by the processor 401, and the processor 401 executes the program stored in the memory 402 to implement the following steps:

[0096] Get the request message sent by the server, which carries the request data;

[0097] Generate a mirror request message corresponding to the request message, where the mirror request message carries the request data;

[0098] Send the mirror request message to the mirror server. The mirror server and the server process are the same.

[0099] Obtain the response message from the image server based on the image request message, which carries the response data.

[0100] Generate test cases based on request data and response data.

[0101] The communication bus 403 mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus 403 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one thick line is used in the diagram, but this does not mean that there is only one bus or one type of bus.

[0102] The memory 402 may include a random access memory (RAM) or a non-volatile memory, such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor 401.

[0103] The above-mentioned processor 401 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc., and can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.

[0104] In another embodiment of the present application, a computer-readable storage medium is provided, which stores a computer program. When the computer program runs on a computer, the computer executes the test case generation method described in the above embodiment.

[0105] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instruction is loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instruction can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instruction is transmitted from a website, computer, server or data center to another website, computer, server or data center by wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (such as a floppy disk, hard disk, tape, etc.), an optical medium (such as a DVD) or a semiconductor medium (such as a solid-state hard disk), etc.

[0106] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0107] The foregoing description is intended only to provide specific embodiments of the present invention, which will enable those skilled in the art to understand and implement the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not intended to be limited to the embodiments shown herein, but is intended to be accorded the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A test case generation method, characterized in that: include: Obtaining a request message sent by the server, wherein the request message carries request data, wherein the request data includes a request method, a request body, and a request network address; Generating a mirror request message corresponding to the request message, wherein the mirror request message carries the request data, including: parsing the request message to obtain the request data, and storing the request data in a database; extracting target request data from the stored request data at intervals of a preset length, wherein the target request data is any request data in the stored request data; and generating the mirror request message according to the target request data; Sending the mirroring request message to a target mirroring server, where the target mirroring server is a mirroring server among the multiple mirroring servers that has not responded to the mirroring request message, and each mirroring server has the same business processing logic and the same processing process as the server; Obtaining a response message fed back by the mirroring server based on the mirroring request message, wherein the response message carries response data, wherein the response data includes a status code and a response body; Generate a test case based on the request data and the response data, including: extracting the hierarchical structure information in the response body as a test inspection basis, splicing the request data and the response data to obtain the test case, wherein the test case includes the request data, the response data and the response body structure corresponding to the response body in the response data.

2. The test case generation method according to any one of claim 1, characterized in that: After generating the test case according to the request data and the response data, the method further includes: The test case is stored.

3. A test case generation system, characterized in that: include: Server side, use case generation side and mirror server side; The server is used to send the request message sent by the client to the use case generation end; The use case generation end is used to obtain a request message sent by a server, wherein the request message carries request data, wherein the request data includes a request method, a request body, and a request network address; generate a mirror request message corresponding to the request message, wherein the mirror request message carries the request data, including: parsing the request message to obtain the request data, and storing the request data in a database; extracting target request data from the stored request data at intervals of a preset length, wherein the target request data is any request data in the stored request data; generating the mirror request message according to the target request data; and sending the mirror request message to a target mirror server, wherein the target mirror server is a mirror server among multiple mirror servers that has not responded to the mirror request message, and each mirror server deploys the same business processing logic and has the same processing process as the server; The mirroring server is configured to process the mirroring request message to obtain a response message, and send the response message to the mirroring server, wherein the response message carries response data, wherein the response data includes a status code and a response body; The use case generation end is further used to obtain a response message fed back by the mirroring service end based on the mirroring request message; and generate a test case according to the request data and the response data, including: extracting the hierarchical structure information in the response body as a test inspection basis, splicing the request data and the response data to obtain the test case, wherein the test case includes the request data, the response data, and a response body structure corresponding to the response body in the response data.

4. An electronic device, characterized in that: include: A processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus; The memory is used to store computer programs; The processor is used to execute the program stored in the memory to implement the test case generation method described in any one of claims 1-2.

5. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the test case generation method according to any one of claims 1 to 2 is implemented.

Citation Information

Patent Citations

  • Test case generation method, system and device and storage medium

    CN112181836A

  • Test method and device, electronic equipment and storage medium

    CN112650689A