Response message testing method and device

By generating and assigning response message Body scripts and testing them in combination with Moco tools, the problem of low response message testing in interface tests is solved, and efficient and accurate response message testing is achieved.

CN119728504APending Publication Date: 2025-03-28BEIJING SHANGYIN MICRO CORE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411896772.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-20
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

In interface testing, when the interface development progress of the requesting party and the service provider is inconsistent, it is difficult for the existing technology to efficiently test response messages, resulting in delays in the test progress and project progress.

Method used

By generating a response message Body script based on the preset corresponding message format, assigning values, generating a response message in combination with the interface document requirements, and using Moco tools to test the response message file to achieve efficient response message testing.

Benefits of technology

This method can efficiently test response messages, reduce the tedious process of manually making response messages, improve test efficiency, and avoid delays in test progress and project progress.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119728504A_ABST
    Figure CN119728504A_ABST
Patent Text Reader

Abstract

The invention provides a response message testing method and device, and relates to the technical field of testing. When the method is executed, a response message Body body script is generated according to a preset corresponding message format, then the response message Body body script is assigned to obtain the assigned response message Body body script, then a response message is generated by utilizing the assigned response message Body body script according to the requirements of an interface document on a request header, a response state and information, and the response message is sent to the interface document. The method comprises the following steps: receiving a response message, generating a response message file in a target format according to the response message, and finally testing the response message file by using a Moco tool. Therefore, the corresponding message can be efficiently tested by assigning the Body script of the response message generated based on the preset corresponding message format, generating the response message, storing the response message as the response message file in the standard format and testing the response message file by using the Moco tool.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of testing technology, and in particular to a response message testing method and device. Background Art

[0002] When doing interface testing, in general, the requester interface and the service provider response program are developed almost at the same time, and the request can be sent through the request interface to get the response result returned by the server. If the development progress of the requester and service provider interfaces is inconsistent, such as the requester interface is completed but the service provider interface is not completed, there is a risk of delaying the test progress and even the entire project progress. In the prior art, mock technology can be used to solve this problem. If mock technology is used, messages with different formats and different parameter responses must be produced. The entire operation process is particularly cumbersome and complicated. If the response message is produced manually to simulate the service response efficiency of different test scenarios is relatively low.

[0003] In summary, how to efficiently test the response message is a problem that technical personnel in this field need to solve urgently. Summary of the invention

[0004] In view of this, the present application provides a response message testing method and device, aiming to efficiently test the response message.

[0005] In a first aspect, the present application provides a response message testing method, comprising:

[0006] Generate the response message Body script according to the preset corresponding message format;

[0007] Assigning a value to the response message Body script to obtain the assigned response message Body script;

[0008] Generate a response message using the assigned response message Body script according to the interface document's requirements for the request header, response status, and information;

[0009] Generate a response message file in a target format according to the response message;

[0010] The response message file is tested using the Moco tool.

[0011] Optionally, generating a response message Body script according to a preset corresponding message format includes:

[0012] Get the fields and data types of the interface document;

[0013] Based on the programming format required by the test, a response message Body script is generated according to the fields and data types of the interface document.

[0014] Optionally, generating a response message according to the interface document's requirements for the request header, response status, and information, using the assigned response message Body script, includes:

[0015] Obtain the interface document's requirements for request headers, response status, and information;

[0016] Generate an interface request header, response status code and message according to the interface document's requirements for request header, response status and information;

[0017] Generate the response message according to the interface request header, the response status code, the message and the assigned response message Body script.

[0018] Optionally, the testing the response message file by using the Moco tool includes:

[0019] Send an interface request to the Moco tool;

[0020] Using the Moco tool to read the response message file in real time and generate a response result;

[0021] The response result is returned to the request interface.

[0022] Optionally, the formats of the response message file include json format, xml format, text format and file format.

[0023] In a second aspect, the present application provides a response message testing device, including:

[0024] The first generating module is used to generate a response message Body script according to a preset corresponding message format;

[0025] An assignment module, used for assigning a value to the response message Body script to obtain the assigned response message Body script;

[0026] A second generating module is used to generate a response message using the assigned response message Body script according to the interface document's requirements for the request header, response status, and information;

[0027] A third generating module, used to generate a response message file in a target format according to the response message;

[0028] A testing module is used to test the response message file using the Moco tool.

[0029] Optionally, the first generating module includes:

[0030] A first acquisition unit, used to acquire fields and data types of an interface document;

[0031] The first generating unit is used to generate a response message Body script based on the programming format required by the test and according to the fields and data types of the interface document.

[0032] Optionally, the second generating module includes:

[0033] A second acquisition unit is used to obtain the requirements of the interface document for the request header, response status and information;

[0034] A second generating unit, used to generate an interface request header, a response status code and a message according to the requirements of the interface document for the request header, the response status and the information;

[0035] The third generating unit is used to generate the response message according to the interface request header, the response status code, the message and the assigned response message Body script.

[0036] Optionally, the test module includes:

[0037] Send an interface request to the Moco tool;

[0038] Using the Moco tool to read the response message file in real time and generate a response result;

[0039] The response result is returned to the request interface.

[0040] Optionally, the formats of the response message file include json format, xml format, text format and file format.

[0041] In a third aspect, an embodiment of the present application provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements a response message testing method as described in any one of the implementation methods in the first aspect of the embodiment of the present application.

[0042] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device executes a response message testing method as described in any one of the implementation methods in the first aspect of the embodiment of the present application.

[0043] The present application provides a response message testing method. When executing the method, first generate a response message Body script according to the preset corresponding message format, then assign the response message Body script to obtain the assigned response message Body script, and then, according to the interface document's requirements for the request header, response status, and information, use the assigned response message Body script to generate a response message, and then generate a response message file in the target format based on the response message, and finally, use the Moco tool to test the response message file. In this way, by assigning a response message Body script generated based on the preset corresponding message format, generating a response message, saving the response message as a response message file in a standard format, and using the Moco tool to test the response message file, the corresponding message can be efficiently tested. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the technical solutions in this embodiment or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0045] Figure 1 A flow chart of a response message testing method provided in an embodiment of the present application;

[0046] Figure 2 A schematic diagram of the structure of a response message testing device provided in an embodiment of the present application;

[0047] Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0048] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. A response message test method and device provided by the present application are used in the field of test technology. The above is only an example and does not limit the application field of the method and device name provided by the present application.

[0049] When doing interface testing, in general, the requester interface and the service provider response program are developed almost at the same time, and the request can be sent through the request interface to get the response result returned by the server. If the development progress of the requester and service provider interfaces is inconsistent, such as the requester interface is completed but the service provider interface is not completed, there is a risk of delaying the test progress and even the entire project progress. In the prior art, mock technology can be used to solve this problem. If mock technology is used, messages with different formats and different parameter responses must be produced. The entire operation process is particularly cumbersome and complicated. If the response message is produced manually to simulate the service response efficiency of different test scenarios is relatively low.

[0050] After research, the inventor proposed the technical solution of the present application. First, a response message Body script is generated according to a preset corresponding message format, and then the response message Body script is assigned to obtain the assigned response message Body script. Then, according to the interface document's requirements for the request header, response status, and information, the assigned response message Body script is used to generate a response message, and then a response message file in the target format is generated based on the response message. Finally, the Moco tool is used to test the response message file. In this way, by assigning a response message Body script generated based on a preset corresponding message format and generating a response message, saving the response message as a response message file in a standard format, and using the Moco tool to test the response message file, the corresponding message can be efficiently tested.

[0051] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. It should be noted that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be combined with each other.

[0052] See also Figure 1 , Figure 1 A flow chart of a response message testing method provided in an embodiment of the present application includes:

[0053] S101: Generate a response message Body script according to a preset corresponding message format.

[0054] Place the interface document in the specified file target, use the program tool class file to read the interface document and analyze it, you can get the interface file fields and data types, and generate the corresponding response message Body script according to the coding format required by the test.

[0055] S102: Assign a value to the response message Body script to obtain the assigned response message Body script.

[0056] According to the test scenario, the Body service return field of the response message is assigned autonomously so that the response message simulates the expected response result, and the program updates the Body field value.

[0057] S103: Generate a response message using the assigned response message Body script according to the interface document's requirements for the request header, response status, and information.

[0058] First, obtain the interface document's requirements for request headers, response status, and information. Then, based on the interface document's requirements for request headers, response status, and information, generate the interface request header, response status code, and message. Finally, generate the response message based on the interface request header, response status code, message, and the assigned response message Body script.

[0059] S104: Generate a response message file in a target format according to the response message.

[0060] Assemble the response message into a response message file of a specific format, where the format of the response message file includes but is not limited to: json, xml, text, file, etc., and store it in the specified directory of the Moco tool. Moco is an easy-to-use mock tool that can get simulated requests and responses by simply configuring request and response objects.

[0061] S105: Use the Moco tool to test the response message file.

[0062] Send an interface request to the Moco tool, use the Moco tool to read the response message file in real time, generate a response result, and return the response result to the request interface. Specifically: Start the Moco tool, send an interface request, the Moco tool implements reading the response message file, and returns the response result to the request interface. During the test, the response message parameter value can be modified in real time, and the latest expected response result can be obtained without stopping the Moco tool.

[0063] In the embodiment provided in the present application, a response message Body script is first generated according to a preset corresponding message format, and then the response message Body script is assigned to obtain the assigned response message Body script, and then, according to the interface document's requirements for the request header, response status, and information, the assigned response message Body script is used to generate a response message, and then a response message file in a target format is generated according to the response message, and finally, the Moco tool is used to test the response message file. In this way, by assigning a response message Body script generated based on a preset corresponding message format, generating a response message, saving the response message as a response message file in a standard format, and using the Moco tool to test the response message file, the corresponding message can be efficiently tested.

[0064] The above are some specific implementations of the response message test method provided in the embodiment of the present application. Based on this, the present application also provides a corresponding device. The device provided in the embodiment of the present application will be introduced from the perspective of functional modularization.

[0065] See also Figure 2 , Figure 2 A structural diagram of a response message test device provided in an embodiment of the present application, the response message test device 200 includes:

[0066] The first generating module 210 is used to generate a response message Body script according to a preset corresponding message format;

[0067] The assignment module 220 is used to assign a value to the response message Body script to obtain the assigned response message Body script;

[0068] The second generating module 230 is used to generate a response message using the assigned response message Body script according to the interface document's requirements for the request header, response status, and information;

[0069] A third generating module 240 is used to generate a response message file in a target format according to the response message;

[0070] The testing module 250 is used to test the response message file using the Moco tool.

[0071] Optionally, the first generating module 210 includes:

[0072] A first acquisition unit, used to acquire fields and data types of an interface document;

[0073] The first generating unit is used to generate a response message Body script based on the programming format required by the test and according to the fields and data types of the interface document.

[0074] Optionally, the second generating module 230 includes:

[0075] A second acquisition unit is used to obtain the requirements of the interface document for the request header, response status and information;

[0076] A second generating unit, used to generate an interface request header, a response status code and a message according to the requirements of the interface document for the request header, the response status and the information;

[0077] The third generating unit is used to generate the response message according to the interface request header, the response status code, the message and the assigned response message Body script.

[0078] Optionally, the testing module 250 includes:

[0079] Send an interface request to the Moco tool;

[0080] Using the Moco tool to read the response message file in real time and generate a response result;

[0081] The response result is returned to the request interface.

[0082] Optionally, the formats of the response message file include json format, xml format, text format and file format.

[0083] The embodiments of the present application also provide corresponding devices and computer storage media for implementing the solutions provided by the embodiments of the present application.

[0084] like Figure 3 As shown, the computer device 01 is in the form of a general computing device. The components of the computer device 01 may include but are not limited to: one or more processors or processing units 03, a system memory 08, and a bus 04 connecting different system components (including the system memory 08 and the processing unit 03).

[0085] Bus 04 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor or a local bus using any of a variety of bus structures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.

[0086] The computer device 01 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 01, including volatile and non-volatile media, removable and non-removable media.

[0087] The system memory 08 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 09 and / or cache memory 10. The computer device 01 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 11 may be used to read and write non-removable, non-volatile magnetic media ( Figure 3 not shown, usually called a "hard drive"). Although Figure 3 Not shown in the figure, a disk drive for reading and writing a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 04 via one or more data medium interfaces. The memory 08 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.

[0088] A program / utility 12 having a set (at least one) of program modules 13 may be stored, for example, in the memory 08, such program modules 13 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination thereof may include an implementation of a network environment. The program modules 13 generally perform the functions and / or methods of the embodiments described herein.

[0089] The computer device 01 may also communicate with one or more external devices 02 (e.g., keyboard, pointing device, display 07, etc.), one or more devices that enable a user to interact with the computer device 01, and / or any device that enables the computer device 01 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed via input / output (I / O) interface 06. Furthermore, the computer device 01 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) via network adapter 05. Figure 3 As shown, the network adapter 05 communicates with other modules of the computer device 01 via the bus 04. It should be understood that although Figure 3Not shown, other hardware and / or software modules may be used in conjunction with computer device 01, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0090] The processor unit 03 executes various functional applications and data processing by running the programs stored in the system memory 08, for example, implementing a response message testing method provided in an embodiment of the present application.

[0091] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0092] Through the description of the above implementation methods, it can be known that those skilled in the art can clearly understand that all or part of the steps in the above-mentioned embodiment method can be implemented by means of software plus a general hardware platform. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a storage medium, such as a read-only memory (ROM) / RAM, a magnetic disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network communication device such as a router) to execute the methods described in each embodiment of the present application or some parts of the embodiments.

[0093] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.

[0094] The above description is merely an exemplary embodiment of the present application and is not intended to limit the protection scope of the present application.

Claims

1. A response message testing method, characterized in that: include: Generate the response message Body script according to the preset corresponding message format; Assigning a value to the response message Body script to obtain the assigned response message Body script; Generate a response message using the assigned response message Body script according to the interface document's requirements for the request header, response status, and information; Generate a response message file in a target format according to the response message; The response message file is tested using the Moco tool.

2. The method according to claim 1, characterized in that The step of generating a response message Body script according to a preset corresponding message format includes: Get the fields and data types of the interface document; Based on the programming format required by the test, a response message Body script is generated according to the fields and data types of the interface document.

3. The method according to claim 1, characterized in that The generating of the response message using the assigned response message Body script according to the interface document's requirements for the request header, response status, and information includes: Obtain the interface document's requirements for request headers, response status, and information; Generate an interface request header, response status code and message according to the interface document's requirements for request header, response status and information; Generate the response message according to the interface request header, the response status code, the message and the assigned response message Body script.

4. The method according to claim 1, characterized in that The testing of the response message file by using the Moco tool includes: Send an interface request to the Moco tool; Using the Moco tool to read the response message file in real time and generate a response result; The response result is returned to the request interface.

5. The method according to claim 1, characterized in that The formats of the response message file include json format, xml format, text format and file format.

6. A response message testing device, characterized in that: include: The first generating module is used to generate a response message Body script according to a preset corresponding message format; An assignment module, used for assigning a value to the response message Body script to obtain the assigned response message Body script; A second generating module is used to generate a response message using the assigned response message Body script according to the interface document's requirements for the request header, response status, and information; A third generating module, used to generate a response message file in a target format according to the response message; A testing module is used to test the response message file using the Moco tool.

7. The device according to claim 6, characterized in that The first generating module comprises: A first acquisition unit, used to acquire fields and data types of an interface document; The first generating unit is used to generate a response message Body script based on the programming format required by the test and according to the fields and data types of the interface document.

8. The device according to claim 6, characterized in that The second generating module comprises: A second acquisition unit is used to obtain the requirements of the interface document for the request header, response status and information; A second generating unit, used to generate an interface request header, a response status code and a message according to the requirements of the interface document for the request header, the response status and the information; The third generating unit is used to generate the response message according to the interface request header, the response status code, the message and the assigned response message Body script.

9. A computer device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the response message testing method according to any one of claims 1 to 5 is implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on the terminal device, the terminal device executes the response message testing method according to any one of claims 1 to 5.