Method and device for generating message request body, computer equipment and storage medium
By defining interface key-value pairs and parameterized fields in Metersphere and Jmeter, using JsonItemExpander to convert the message request body, the problem of single interface automation test case scenario is solved, and flexible response to different business data and more comprehensive testing coverage is achieved. .
Patent Information
- Application Number
- CN202411372062.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2044-09-29
AI Technical Summary
When Metersphere and Jmeter are automated testing, they cannot flexibly test more business scenarios according to different business data, resulting in a single use case scenario and cannot adapt to different data conditions.
By defining the keys and values of the interface to be tested, the fields that need to be parameterized are obtained, the fields that need to be parameterized are expanded and added to the data structure, and the JsonItemExpander is used to convert them into a message request body, and the structure of the interface request body is dynamically adjusted.
It realizes the flexibility of interface automation use cases, can automatically match and expand according to different business data, cover more test scenarios, and avoid dependence on fixed design data.
Smart Images

Figure CN119311587A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to a method, device, computer equipment and storage medium for generating a message request body. Background Art
[0002] MeterSphere is a comprehensive test management platform. Its interface automation testing function allows testers to automatically verify the functionality, performance and stability of software interfaces by writing test scripts. Through MeterSphere, testers can more conveniently manage test resources, perform test tasks, and quickly locate problems, thereby improving overall test efficiency and software quality.
[0003] JMeter is an open source performance testing tool, and its interface automation testing function is also powerful. JMeter performs stress testing on software interfaces by simulating the behavior of a large number of concurrent users to evaluate the performance of interfaces under high load. JMeter's interface automation testing function can not only help testers find potential performance bottlenecks, but also verify the stability of interfaces in various complex scenarios.
[0004] Currently, when Metersphere and Jmeter perform interface automation testing, the number of item details in the response result of each request of the previous interface request is not fixed, resulting in the fact that when the next interface request is made, it is not known how many items of the message body need to be written to request.
[0005] In the prior art, when Metersphere and Jmeter perform interface automation testing, only fixed use case data can be pre-designed. After the basic use case data is determined, there will be a fixed number of items. Subsequent requests can parameterize variables according to the fixed number and form message body requests. This method has a single use case scenario and cannot flexibly test more business scenarios according to different business data. Summary of the invention
[0006] The purpose of the embodiments of the present invention is to propose a method, device, computer equipment and storage medium for generating a message request body, so as to solve the problem that the use case scenario of Metersphere and Jmeter in the prior art is single when performing interface automation testing, and it is impossible to flexibly automate more business scenarios according to different business data.
[0007] In order to solve the above technical problems, the present invention provides a method for generating a message request body, which adopts the following technical solution, including:
[0008] S1. Define the keys and values of the interface to be tested, as well as the fields that need to be parameterized;
[0009] S2. Get the fields that need to be parameterized in the item corresponding to multiple detail lines of a master order;
[0010] S3, adding the character string of the field that needs to be parameterized in the entry item to the data structure Map for storing key-value pairs;
[0011] S4. Obtain the number of items to be expanded from the response result returned by the interface of the previous query class, match multiple data extraction parameters through Metesphere, use the data result returned by the interface of the previous query class as a parameter, and pass the obtained parameter to the encapsulation class JsonItemExpander, call the encapsulation class JsonItemExpander through the imported ly.mp.ms.common.jar, and convert it into a message request body;
[0012] S5. Run the interface test case to be tested and output the message request body after the item is extended;
[0013] S6. Set the output message request body into the Meterstphere parameter.
[0014] Preferably, the step of S1, defining the keys and values of the interface to be tested, and the fields to be parameterized, specifically includes:
[0015] S11, defining the overall structure identifier of the request message body;
[0016] S12. Create two HashMap key-value pair data structures for head and items respectively, and add the message fields to be generated into the key-value pairs.
[0017] Preferably, the step of S2, obtaining the fields that need to be parameterized in the item corresponding to multiple detail lines of a master order, specifically comprises:
[0018] S21. Use the beashell script syntax of Meterstphere to obtain the writing method of multiple detailed data of the interface query result in the previous step;
[0019] S22. By declaring a character variable, the parameter value obtained in the previous step is passed to the character variable.
[0020] Preferably, the step of adding the character string of the field to be parameterized in the item to a data structure Map for storing key-value pairs in S3 specifically includes:
[0021] S31. Create a HashMap key-value pair data structure for the fields that need to be extended and parameterized;
[0022] S32. Add the fields that need to be extended and parameterized into the key-value pairs.
[0023] Preferably, the step of S4, obtaining the number of items to be expanded from the response result returned by the interface of the previous query class, matching multiple data extraction parameters through Metesphere, taking the data result returned by the interface of the previous query class as a parameter, and passing the obtained parameter to the encapsulation class JsonItemExpander, calling the encapsulation class JsonItemExpander through the imported ly.mp.ms.common.jar, and converting into a message request body specifically includes:
[0024] S41, obtaining the number of items that need to be expanded from the response result returned by the interface of the previous query class, and taking the number of fields that need to be expanded in the response result of the previous interface query as the number of items that need to be expanded;
[0025] S42. declare an integer parameter and assign the result of the previous step to the integer parameter;
[0026] S43. The data result returned by the interface of the previous query class is passed as a parameter to the getJSONStr method in the encapsulation class JsonItemExpander, and converted into a message request body.
[0027] Preferably, the step of running the interface test case to be tested and outputting the message request body after the item item is extended specifically includes:
[0028] S51, converting the message request body into a character string that can be recognized by Meterstphere;
[0029] S52: Run the interface test case to be tested, and output the message request body after the item item is expanded.
[0030] Preferably, the step of setting the output message request body into the Meterstphere parameter in S6 specifically includes:
[0031] S61, extracting a message string variable req_array from the message request body;
[0032] S62. Set the message string variable req_array to the parameter jsonReqArray that can be recognized by Meterstphere.
[0033] In order to solve the above technical problems, the present invention further provides a device for generating a message request body, which adopts the following technical solution, including:
[0034] Definition module, which is used to define the keys and values of the interface to be tested, as well as the fields that need to be parameterized;
[0035] The acquisition module is used to obtain the fields that need to be parameterized in the item corresponding to multiple detail lines of a master order;
[0036] An adding module, used for adding the string of the field to be parameterized in the entry item to a data structure Map for storing key-value pairs;
[0037] The calling module is used to obtain the number of items to be expanded from the response result returned by the interface of the previous query class, match multiple data extraction parameters through Metesphere, use the data result returned by the interface of the previous query class as a parameter, and pass the obtained parameter to the encapsulation class JsonItemExpander, call the encapsulation class JsonItemExpander through the imported ly.mp.ms.common.jar, and convert it into a message request body;
[0038] An output module, used to run the interface test case to be tested, and output the message request body after the item item is expanded;
[0039] The setting module is used to set the output message request body into the Meterstphere parameters.
[0040] In order to solve the above technical problems, the present invention also provides a computer device, which adopts the technical solution described below, including a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the above-mentioned method for generating a message request body are implemented.
[0041] In order to solve the above technical problems, the present invention also provides a computer-readable storage medium, which adopts the technical solution described below, and stores computer-readable instructions on the computer-readable storage medium. When the computer-readable instructions are executed by the processor, the steps of the above-mentioned method for generating a message request body are implemented.
[0042] Compared with the prior art, the present invention has the following beneficial effects: by adding a custom script to the interface test, defining the interface template, and automatically expanding the item details according to the number of items obtained in the previous step interface response, and generating a complete message body request; making the interface automation use case more flexible, not relying on fixed design data, and automatically matching different data to run normally and directly; automatically testing more business scenarios according to different business data, making the automation test case coverage of the scenario more comprehensive. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the scheme in the present invention, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 is an exemplary system architecture diagram in which the present invention can be applied;
[0045] Figure 2 is a flow chart of an embodiment of a method for generating a message request body of the present invention;
[0046] Figure 3 It is a structural schematic diagram of an embodiment of a device for generating a message request body of the present invention;
[0047] Figure 4 It is a schematic structural diagram of an embodiment of a computer device of the present invention. DETAILED DESCRIPTION
[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present invention; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention; the terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present invention or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0049] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0050] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings.
[0051] The request body plays a vital role in the HTTP protocol. It is used to transmit the data sent by the client to the server. As an optional component of the HTTP request, the request body carries the parameters, content or data required for the request, enabling the client to exchange data effectively with the server.
[0052] Specifically, the message request body mainly contains various types of data that the client wants to send to the server. This data may exist in multiple formats, including but not limited to form data (application / x-www-form-urlencoded), JSON data (application / json), files (multipart / form-data), etc. The specific format is usually specified by the Content-Type field in the request header so that the server can correctly parse and process this data.
[0053] The message request body enables the client to pass complex, structured data to the server, supporting a variety of network application scenarios such as user login, data submission, file upload, etc. For example, in the shopping cart settlement scenario of an e-commerce platform, the user's purchase information (such as product ID, quantity, etc.) can be sent to the server in JSON format through the request body, thereby realizing the order generation and payment process.
[0054] like Figure 1 As shown, the system architecture 100 may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 is used to provide a medium for a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0055] The user can use the first terminal device 101, the second terminal device 102 or the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0056] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0057] The server 105 may be a server that provides various services, for example, a background server that provides support for pages displayed on the first terminal device 101 , the second terminal device 102 , and the third terminal device 103 .
[0058] It should be noted that the method for generating a message request body provided in the embodiment of the present invention is generally executed by a server / terminal device, and accordingly, the device for generating a message request body is generally arranged in the server / terminal device.
[0059] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0060] Embodiment 1
[0061] Continue to refer Figure 2 , shows a flow chart of an embodiment of a method for generating a message request body of the present invention. The method for generating a message request body comprises the following steps:
[0062] Step S1, define the keys and values of the interface to be tested, and the fields that need to be parameterized.
[0063] In this embodiment, the electronic device (eg, Figure 1 The server / terminal device shown in the figure can receive the request for generating the message request body through a wired connection or a wireless connection. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAXX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0064] Here, the custom script has different request body fields for different interfaces to be tested. In this embodiment, the format and fields of the custom message request body are defined using the beanshell script syntax in Metersphere, which is compatible with the java syntax.
[0065] In this embodiment, step S1 may further include the following steps:
[0066] S11. Define the overall structure identifier of the request message body.
[0067] Take the request body required by the following interface as an example:
[0068]
[0069]
[0070] String headName = "head"; / / Fill in the blank if not needed. Considering that some request bodies may not have such header information wrapped by head, it can be left blank.
[0071] String itemName = "items"; / / Required. This method is mainly used to expand multiple detail rows. In this case, there must be an items tag to wrap the details, so it is required. At the same time, the items value can be freely defined and can be called other dataList, datas, etc.
[0072] S12. Create two HashMap key-value pair data structures for head and items respectively, and add the message fields to be generated into the key-value pairs.
[0073] For example, two HashMap key-value pair data structures can be named headMap and itemMap respectively.
[0074] If the value needs to match multiple entries, then the value must be written as xxxx_ALL according to the format rules, where xxxx is the corresponding key. If the value does not need to match multiple entries, then it can be parameterized according to the MS syntax or written as a fixed value. For example, in the following example: XXXX represents containerNo and id.
[0075] For example, you can predefine the format of one value and multiple values:
[0076] A value: the key value is: "XXXX":"${XXXX}";
[0077] Multiple values: The key value is: "XXXX":"XXXX_ALL".
[0078] HashMap headMap = new HashMap();
[0079] headMap.put("waybillNo", "${waybillNo}");
[0080] headMap.put("driverName", "张三");
[0081] headMap.put("status", "4");
[0082] HashMap itemMap = new HashMap();
[0083] itemMap.put("waybillNo", "${waybillNo}");
[0084] itemMap.put("containerNo", "containerNo_ALL");
[0085] itemMap.put("id", "id_ALL");
[0086] itemMap.put("status", "3");
[0087] itemMap.put("pickQuantity", "pickQuantity_ALL");
[0088] itemMap.put("realityPickTime",
[0089] "${__timeShift(yyyy-MM-dd HH:mm:ss,,,,)}");
[0090] itemMap.put("deliverQuantity", "");
[0091] itemMap.put("deliveryArrivalTime", "");
[0092] Step S2, obtain the fields that need to be parameterized in the item where one master order corresponds to multiple detail lines.
[0093] In this embodiment, step S2 may specifically further include the steps:
[0094] S21. Use the beashell script syntax of Meterstphere to obtain the writing method of multiple detailed data of the interface query result in the previous step.
[0095] For example, you can use the code vars.get("containerNo_ALL"); to get the parameter values of all fields that need to obtain multiple detailed data.
[0096] S22. By declaring a character variable, the parameter value obtained in the previous step is passed to the character variable.
[0097] For example, you can use the code:
[0098] String id_ALL=vars.get("id_ALL");
[0099] String containerNo_ALL=vars.get("containerNo_ALL");
[0100] String planQuantity_ALL=vars.get("planQuantity_ALL");
[0101] Step S3, adding the character string of the field that needs to be parameterized in the entry item to the data structure Map for storing key-value pairs.
[0102] Map is a data structure used to store key-value pairs in JAVA programming. This data structure is used in the Metersphere Beanshell script.
[0103] In this embodiment, step S3 may further include the following steps:
[0104] S31. Create a HashMap key-value pair data structure for the fields that need to be extended and parameterized.
[0105] S32. Add the fields that need to be extended and parameterized into the key-value pairs.
[0106] For example, when adding the fields that need to be extended and parameterized into the key-value pair, you can name it valueMap. The key is the content in the quotation marks on the left, which is consistent with XXXX_ALL defined in step S1, and the value is the string of the extended parameterized field obtained in step S2.
[0107] For example, you can use code to implement:
[0108] HashMap valueMap=new HashMap();
[0109] valueMap.put("id_ALL",id_ALL);
[0110] valueMap.put("containerNo_ALL",containerNo_ALL);
[0111] valueMap.put("pickQuantity_ALL",planQuantity_ALL);
[0112] Step S4, obtain the number of items to be expanded from the response result returned by the interface of the previous query class, match multiple data extraction parameters through Metesphere, use the data result returned by the interface of the previous query class as a parameter, and pass the obtained parameters to the encapsulation class JsonItemExpander, call the encapsulation class JsonItemExpander through the imported ly.mp.ms.common.jar, and convert it into a message request body.
[0113] In this embodiment, step S4 may further include the following steps:
[0114] S41. Obtain the number of entries that need to be expanded from the response result returned by the interface of the previous query class, and use the number of fields that need to be expanded in the response result of the previous interface query as the number of items that need to be expanded.
[0115] For example, you can use the beanshell script syntax in Meterstphere: ${id_matchNr}.
[0116] S42. Declare an integer parameter and assign the result of the previous step to the integer parameter.
[0117] For example, it can be implemented using int num = ${id_matchNr}.
[0118] S43. The data result returned by the interface of the previous query class is passed as a parameter to the getJSONStr method in the encapsulation class JsonItemExpander, and converted into a message request body.
[0119] For example, the headName, itemName, headMap, itemMap defined in step S1, the Map value valueMap generated in step S3, and the number of extensions num obtained in step S4, these 6 values are passed as parameters to the getJSONStr method in the encapsulation class JsonItemExpander and converted into a complete message request body.
[0120] For example, you can use code to implement:
[0121] int num = ${id_matchNr};
[0122] String newStr=JsonItemExpander.getJSONStr(headMap,
[0123] itemMap,num,valueMap);
[0124] return newStr;
[0125] Step S5, running the interface test case to be tested, and outputting the message request body after the extended entry item.
[0126] In this embodiment, step S5 may further include the following steps:
[0127] S51. Convert the message request body into a character string that can be recognized by Meterstphere.
[0128] MeterSphere supports data exchange formats such as JSON and XML. If the message is in JSON format, you can use Java libraries such as Jackson or Gson to parse and generate strings. These libraries can serialize Java objects into JSON strings, or deserialize JSON strings into Java objects.
[0129] In Java or other supported programming languages, write logic to parse the message request body and convert it to a string. Make sure all necessary fields are processed and converted correctly.
[0130] Send the converted string to MeterSphere for testing to verify whether it can be parsed and processed correctly. If you encounter problems, debug and adjust according to the log or error information of MeterSphere.
[0131] S52: Run the interface test case to be tested, and output the message request body after the extended item item.
[0132] After running the interface test case to be tested, the expanded message will be automatically obtained. The output result has been stored in the background console, which can be used in the next step to use ${xxx} to call the overall message request body xxx.
[0133] Step S6, setting the output message request body into the Meterstphere parameter.
[0134] In this embodiment, step S6 may further include the following steps:
[0135] S61. Extract the message character string variable req_array from the message request body.
[0136] All of the above steps S1 to S4 are in the custom static method isVal() (code structure: public static String isVal(){S1,S2,S3,S4}), so it is necessary to extract the complete message generated by step S4 and set it into the string variable req_array.
[0137] This can be achieved by using the following syntax: String req_array = isVal().
[0138] S62. Set the message string variable req_array to the parameter jsonReqArray that can be recognized by Meterstphere.
[0139] For example, you can use code to implement:
[0140] vars.put("jsonReqArray",req_array);
[0141] In some optional implementations of this embodiment, step S6 may further include the following steps:
[0142] S7, call message request body.
[0143] The next step of the interface request body can be directly used by using ${jsonReqArray} to call the message request body.
[0144] For example, the complete sample code can be:
[0145] import java.util.*;
[0146] import com.ly.mp.ms.common.*;
[0147] public static String isVal(){
[0148] / / The first step: define the keys and values of the message interface, and which ones need to be parameterized. One value: the key value is: "XXXX":"${XXXX}"; multiple values: the key value is: "XXXX":"XXXX_ALL"
[0149] String headName = "head"; / / fill in blank if not needed
[0150] String itemName = "items"; / / Required
[0151] HashMap headMap = new HashMap();
[0152] headMap.put("waybillNo", "${waybillNo}");
[0153] headMap.put("driverName", "Zhang San");
[0154] headMap.put("identityId", "34567");
[0155] headMap.put("contactInformation", "13622222222");
[0156] headMap.put("carPlate", "Yue A12345");
[0157] headMap.put("carTrailer", "Yue A12345");
[0158] headMap.put("carType", "TRUCK - B");
[0159] headMap.put("expectedArrivalDate", "2024 - 01 - 04 13:00:00");
[0160] headMap.put("status", "4");
[0161] HashMap itemMap = new HashMap();
[0162] itemMap.put("waybillNo", "${waybillNo}");
[0163] itemMap.put("containerNo", "containerNo_ALL");
[0164] itemMap.put("id", "id_ALL");
[0165] itemMap.put("status", "3");
[0166] itemMap.put("pickQuantity","pickQuantity_ALL");
[0167] itemMap.put("realityPickTime","${__timeShift(yyyy-MM-dd HH:mm:ss,,,,)}");
[0168] itemMap.put("deliverQuantity","");
[0169] itemMap.put("deliveryArrivalTime","");
[0170] / / Step 2: Get the string of the fields that need to be extended and parameterized in all items
[0171] String id_ALL=vars.get("id_ALL");
[0172] String containerNo_ALL=vars.get("containerNo_ALL");
[0173] String planQuantity_ALL=vars.get("planQuantity_ALL");
[0174] / / Step 3: Add the string of the field that needs to be expanded and parameterized in item to Map. The quotation marks in front are consistent with the definition, and then obtain multiple matching results in the previous step.
[0175] HashMap valueMap=new HashMap();
[0176] valueMap.put("id_ALL",id_ALL);
[0177] valueMap.put("containerNo_ALL",containerNo_ALL);
[0178] valueMap.put("pickQuantity_ALL",planQuantity_ALL);
[0179] / / Step 4: Get the number of items to be expanded from the response result, and pass the parameters obtained in the above 4 steps to the encapsulation class
[0180] int num = ${id_matchNr};
[0181] String newStr=
[0182] JsonItemExpander.getJSONStr(headName,itemName,headMap,itemMap,num,valueMap);
[0183] return newStr;
[0184] }
[0185] / / Step 5: Output the message after the extended item
[0186] String req_array = isVal();
[0187] / / System.out.println("jsonString="+req_array);
[0188] log.info("req_array==="+req_array);
[0189] / / Step 6: Set the output message characters into the MS parameters
[0190] vars.put("jsonReqArray",req_array);
[0191] / / Step 7: The next step interface request body directly calls ${jsonReqArray} to use.
[0192] It should be emphasized that in order to further ensure the privacy and security of the message request body information generated above, the message request body information generated above can also be stored in a blockchain node.
[0193] The blockchain referred to in this invention is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0194] The beneficial effects of implementing this embodiment are as follows: by adding a custom script in the interface test, defining the interface template, and automatically expanding the item details and generating a complete message body request according to the number of items obtained in the previous step interface response; making the interface automation use case more flexible, not relying on fixed design data, and automatically matching different data to run normally and directly; automatically testing more business scenarios based on different business data, making the automation test case coverage of scenarios more comprehensive.
[0195] The present invention can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present invention can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present invention can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0196] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0197] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0198] Embodiment 2
[0199] Further references Figure 3 , as a response to the above Figure 2 The present invention provides an embodiment of a device for generating a message request body, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0200] like Figure 3 As shown, the message request body generating device 70 described in this embodiment includes: a definition module 71, an acquisition module 72, a joining module 73, a calling module 74, an output module 75 and a setting module 76.
[0201] in:
[0202] A definition module 71 is used to define the keys and values of the interface to be tested, as well as the fields that need to be parameterized;
[0203] The acquisition module 72 is used to acquire the fields that need to be parameterized in the item corresponding to multiple detail lines of a master order;
[0204] An adding module 73 is used to add the character string of the field that needs to be parameterized in the entry item to a data structure Map for storing key-value pairs;
[0205] The calling module 74 is used to obtain the number of items to be expanded from the response result returned by the interface of the previous query class, match multiple data extraction parameters through Metesphere, use the data result returned by the interface of the previous query class as a parameter, and pass the obtained parameter to the encapsulation class JsonItemExpander, call the encapsulation class JsonItemExpander through the imported ly.mp.ms.common.jar, and convert it into a message request body;
[0206] The output module 75 is used to run the interface test case to be tested and output the message request body after the item item is expanded;
[0207] The setting module 76 is used to set the output message request body into the Meterstphere parameter.
[0208] The beneficial effects of implementing this embodiment are as follows: by adding a custom script in the interface test, defining the interface template, and automatically expanding the item details and generating a complete message body request according to the number of items obtained in the previous step interface response; making the interface automation use case more flexible, not relying on fixed design data, and automatically matching different data to run normally and directly; automatically testing more business scenarios based on different business data, making the automation test case coverage of scenarios more comprehensive.
[0209] Embodiment 3
[0210] To solve the above technical problems, the embodiment of the present invention also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0211] The above-mentioned computer device 8 includes a memory 81, a processor 82, and a network interface 83 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 8 having components of a memory 81, a processor 82, and a network interface 83, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application specific integrated circuit (ASIC), a programmable gate array (FPGA), a digital processor (DSP), an embedded device, etc.
[0212] The computer device may be a desktop computer, a notebook computer, a PDA, a cloud server, etc. The computer device may interact with the user through a keyboard, a mouse, a remote control, a touch pad, or a voice control device.
[0213] The memory 81 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 81 may be an internal storage unit of the computer device 8, such as a hard disk or memory of the computer device 8. In other embodiments, the memory 81 may also be an external storage device of the computer device 8, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. equipped on the computer device 8. Of course, the memory 81 may also include both the internal storage unit of the computer device 8 and its external storage device. In this embodiment, the memory 81 is generally used to store the operating system and various application software installed on the computer device 8, such as computer-readable instructions for generating a message request body method, etc. In addition, the memory 81 can also be used to temporarily store various types of data that have been output or are to be output.
[0214] The processor 82 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 82 is generally used to control the overall operation of the computer device 8. In this embodiment, the processor 82 is used to run the computer-readable instructions stored in the memory 81 or process data, such as running the computer-readable instructions of the method for generating a message request body.
[0215] The network interface 83 may include a wireless network interface or a wired network interface. The network interface 83 is generally used to establish a communication connection between the computer device 8 and other electronic devices.
[0216] The beneficial effects of implementing this embodiment are as follows: by adding a custom script in the interface test, defining the interface template, and automatically expanding the item details and generating a complete message body request according to the number of items obtained in the previous step interface response; making the interface automation use case more flexible, not relying on fixed design data, and automatically matching different data to run normally and directly; automatically testing more business scenarios based on different business data, making the automation test case coverage of scenarios more comprehensive.
[0217] Embodiment 4
[0218] The present invention also provides another embodiment, namely, providing a computer-readable storage medium, which stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the method for generating a message request body as described above.
[0219] The beneficial effects of implementing this embodiment are as follows: by adding a custom script in the interface test, defining the interface template, and automatically expanding the item details and generating a complete message body request according to the number of items obtained in the previous step interface response; making the interface automation use case more flexible, not relying on fixed design data, and automatically matching different data to run normally and directly; automatically testing more business scenarios based on different business data, making the automation test case coverage of scenarios more comprehensive.
[0220] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the various embodiment methods of the present invention.
[0221] Obviously, the embodiments described above are only some embodiments of the present invention, rather than all embodiments. The preferred embodiments of the present invention are given in the accompanying drawings, but they do not limit the patent scope of the present invention. The present invention can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive. Although the present invention has been described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific embodiments, or to perform equivalent replacements for some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of the present invention, directly or indirectly used in other related technical fields, is also within the scope of patent protection of the present invention.
Claims
1. A method for generating a message request body, characterized in that: The steps include: S1. Define the keys and values of the interface to be tested, as well as the fields that need to be parameterized; S2. Get the fields that need to be parameterized in the item corresponding to multiple detail lines of a master order; S3, adding the character string of the field that needs to be parameterized in the entry item to the data structure Map for storing key-value pairs; S4. Obtain the number of items to be expanded from the response result returned by the interface of the previous query class, match multiple data extraction parameters through Metesphere, use the data result returned by the interface of the previous query class as a parameter, and pass the obtained parameter to the encapsulation class JsonItemExpander, call the encapsulation class JsonItemExpander through the imported ly.mp.ms.common.jar, and convert it into a message request body; S5. Run the interface test case to be tested and output the message request body after the item is extended; S6. Set the output message request body into the Meterstphere parameter.
2. The method for generating a message request body according to claim 1, characterized in that: The step of S1, defining the keys and values of the interface to be tested, and the fields to be parameterized, specifically includes: S11, defining the overall structure identifier of the request message body; S12. Create two HashMap key-value pair data structures for head and items respectively, and add the message fields to be generated into the key-value pairs.
3. The method for generating a message request body according to claim 1, characterized in that: The step S2 of obtaining the fields that need to be parameterized in the item corresponding to multiple detail lines of a master order specifically includes: S21. Use the beashell script syntax of Meterstphere to obtain the writing method of multiple detailed data of the interface query result in the previous step; S22. By declaring a character variable, the parameter value obtained in the previous step is passed to the character variable.
4. The method for generating a message request body according to claim 1, characterized in that: The step of adding the character string of the field to be parameterized in the item to a data structure Map for storing key-value pairs specifically includes: S31. Create a HashMap key-value pair data structure for the fields that need to be extended and parameterized; S32. Add the fields that need to be extended and parameterized into the key-value pairs.
5. The method for generating a message request body according to claim 1, characterized in that: The step S4, obtaining the number of items to be expanded from the response result returned from the interface of the previous query class, matching multiple data extraction parameters through Metesphere, taking the data result returned by the interface of the previous query class as a parameter, and passing the obtained parameter to the encapsulation class JsonItemExpander, calling the encapsulation class JsonItemExpander through the imported ly.mp.ms.common.jar, and converting it into a message request body specifically includes: S41, obtaining the number of items that need to be expanded from the response result returned by the interface of the previous query class, and taking the number of fields that need to be expanded in the response result of the previous interface query as the number of items that need to be expanded; S42. declare an integer parameter and assign the result of the previous step to the integer parameter; S43. The data result returned by the interface of the previous query class is passed as a parameter to the getJSONStr method in the encapsulation class JsonItemExpander, and converted into a message request body.
6. The method for generating a message request body according to claim 1, characterized in that: The step of running the interface test case to be tested and outputting the message request body after the item item is extended specifically includes: S51, converting the message request body into a character string that can be recognized by Meterstphere; S52: Run the interface test case to be tested, and output the message request body after the item item is expanded.
7. The method for generating a message request body according to claim 1, characterized in that: The step of setting the output message request body into the Meterstphere parameter in S6 specifically includes: S61, extracting a message string variable req_array from the message request body; S62. Set the message string variable req_array to the parameter jsonReqArray that can be recognized by Meterstphere.
8. A device for generating a message request body, characterized in that: include: Definition module, which is used to define the keys and values of the interface to be tested, as well as the fields that need to be parameterized; The acquisition module is used to obtain the fields that need to be parameterized in the item corresponding to multiple detail lines of a master order; An adding module, used for adding the string of the field to be parameterized in the entry item to a data structure Map for storing key-value pairs; The calling module is used to obtain the number of items to be expanded from the response result returned by the interface of the previous query class, match multiple data extraction parameters through Metesphere, use the data result returned by the interface of the previous query class as a parameter, and pass the obtained parameter to the encapsulation class JsonItemExpander, call the encapsulation class JsonItemExpander through the imported ly.mp.ms.common.jar, and convert it into a message request body; An output module, used to run the interface test case to be tested, and output the message request body after the item item is expanded; The setting module is used to set the output message request body into the Meterstphere parameters.
9. A computer device, comprising a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the method for generating a message request body according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the method for generating a message request body according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Request body generation method and device based on interface document, and computer equipment
CN112506769A
Test case generation method and device, storage medium and electronic device
CN117687903A
Software development platform using method
CN118035107A