Mock debugging method, device, medium and equipment
By setting a mock debugging module between the request sender and the receiver and using mock objects to simulate API interface functions, the problem of low debugging efficiency in the existing technology is solved and efficient business process debugging is achieved.
Patent Information
- Application Number
- CN202210013037.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-07
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2042-01-07
AI Technical Summary
Existing business process debugging relies on actually calling API interfaces, resulting in low debugging efficiency, especially when the interface is blocked, the entire process is blocked.
By setting up the mock debugging module and using the mock object to simulate the API interface function, debugging requests can be processed without actually calling the API interface, thereby improving debugging efficiency.
During the debugging process, the debugging results can be obtained without actually calling the API interface, which improves the debugging efficiency and prevents process congestion caused by interface blocking.
Smart Images

Figure CN114416166B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of testing technology, and in particular to a mock debugging method, apparatus, medium, and equipment. Background Art
[0002] In the internet traffic diversion business, the diversion company typically defines a set of standardized API interfaces, which are then implemented by an external partner company. Finally, both parties conduct business integration and joint debugging. When developing and debugging a business, the diversion company needs to call the API interfaces to debug the business process.
[0003] Current business process debugging relies on API services, requiring actual API calls to perform debugging. However, if any API is blocked, the entire debugging process will be blocked, resulting in low debugging efficiency. Summary of the Invention
[0004] The embodiments of the present application provide a mock debugging method, apparatus, medium, and device, which can simulate different API interfaces through mock objects and process debugging requests through mock objects without calling API interfaces for debugging, thereby improving the efficiency of API debugging.
[0005] In a first aspect, an embodiment of the present application provides a mock debugging method, the method being performed by a mock debugging module, the mock debugging module being disposed between a request sender and a request receiver, the method comprising:
[0006] receiving a task request from the request sender;
[0007] Determining whether the task request is a debugging request;
[0008] If the task request is a debugging request, matching a corresponding target mock object from a preset mock object set according to the debugging request; wherein each mock object is used to simulate an API interface of the request recipient;
[0009] Processing the debugging request through the target mock object to obtain mock data;
[0010] A debugging result is determined according to the mock data.
[0011] In one embodiment of the present application, determining whether the task request is a debugging request includes:
[0012] Determining user information included in the task request;
[0013] Determine whether the preset debugging user information library includes the user information; wherein the debugging user information library includes at least one user information for debugging;
[0014] If the debugging user information library includes the user information, the task request is determined to be a debugging request; if the debugging user information library does not include the user information, the API interface corresponding to the request receiver is called to process the task request.
[0015] In one embodiment of the present application, each of the mock objects is set as follows:
[0016] Determine the target API interface corresponding to the current mock object;
[0017] According to the function of the target API interface, obtain a custom function that can return mock data;
[0018] Fill the custom function into the blank object template to obtain the filled current mock object.
[0019] In one embodiment of the present application, after obtaining a custom function capable of returning mock data according to the function of the target API interface, the method further includes:
[0020] Determine whether there is an associated API interface that has a mutually dependent coupling relationship with the target API interface;
[0021] If it exists, obtain the corresponding coupling function according to the function of the associated API interface;
[0022] Integrate the coupling function into the custom function.
[0023] In one embodiment of the present application, the debugging request includes a debugging parameter value;
[0024] Processing the debugging request through the target mock object to obtain mock data includes:
[0025] Call the target custom function of the target mock object according to the debugging parameter value;
[0026] Obtain the return value of the target custom function;
[0027] The preset data template is filled with the return value to obtain the filled mock data.
[0028] In one embodiment of the present application, determining a debugging result according to the mock data includes:
[0029] Determining target result comparison information corresponding to the request sender from a preset result comparison library; wherein the result comparison library includes at least one request sender and result comparison information corresponding to the request sender, and each type of result comparison information includes a correspondence between at least one debugging result and mock data;
[0030] The debugging result is determined according to the target result comparison information and the mock data.
[0031] In one embodiment of the present application, the method further includes:
[0032] If it is detected that at least one API interface of the request recipient has generated an update event, determine the mock object to be updated corresponding to the updated API interface;
[0033] Update the mock object according to the function of the update API interface.
[0034] In a second aspect, an embodiment of the present invention provides a mock debugging device, wherein the mock debugging module is provided between a request sender and a request receiver, and the module includes:
[0035] A task receiving unit, configured to receive a task request from the request sender;
[0036] a debugging request judging unit, configured to determine whether the task request is a debugging request;
[0037] A mock object matching unit is configured to match a corresponding target mock object from a preset mock object set according to the debugging request when the task request is a debugging request, wherein each mock object is used to simulate an API interface of the request recipient;
[0038] A mock data acquisition unit, configured to process the debugging request through the target mock object to obtain mock data;
[0039] The debugging result determining unit is used to determine the debugging result according to the mock data.
[0040] In a third aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the mock debugging method as described in the embodiment of the present application.
[0041] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the mock debugging method as described in the embodiment of the present application when executing the computer program.
[0042] The technical solution provided by the embodiments of the present application, by setting up a mock debugging module between the request sender and the request receiver, executes the debugging request sent by the request sender through multiple mock objects included in the mock debugging module for simulating the API interface of the receiver, and returns the debugging results. The solution provided by the embodiments of the present application simulates the functions of the API interface through mock objects, so the debugging results can be obtained during debugging without actually calling the API interface, thereby improving debugging efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 This is a flowchart of the mock debugging method provided in Example 1 of the present application;
[0044] Figure 2 Flowchart of the mock debugging method provided in the second embodiment of the present invention;
[0045] Figure 3 Flowchart of the mock object setting method provided in the second embodiment of the present invention;
[0046] Figure 4 This is a flowchart of the mock data acquisition method provided in Example 3 of the present invention;
[0047] Figure 5 This is a flowchart of a task request determination method provided in Embodiment 4 of the present invention;
[0048] Figure 6 This is a structural block diagram of the mock debugging device provided in Example 5 of the present invention;
[0049] Figure 7 This is a structural block diagram of the mock debugging device provided in Example 5 of the present invention;
[0050] Figure 8 This is a structural diagram of an electronic device provided in Example 7 of the present application. DETAILED DESCRIPTION
[0051] The present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are intended only to illustrate the present application and are not intended to limit the present application. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions of the present application, not all of the structures.
[0052] Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe the steps as sequential processes, many of the steps can be implemented in parallel, concurrently, or simultaneously. In addition, the order of the steps can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0053] Example 1
[0054] Figure 1 This is a flowchart of the mock debugging method provided in Example 1 of the present application. The method is executed by a mock debugging module. The mock debugging module is set between the request sender and the request receiver. The module can be implemented by software and / or hardware and can be integrated into an electronic device.
[0055] like Figure 1 As shown, the mock debugging method includes:
[0056] S110: Receive a task request from the request sender.
[0057] Among them, in the Internet traffic diversion business, the diversion company usually defines a set of standardized API interfaces, and then the external cooperative company implements the set of API interfaces, and finally the two parties carry out business docking and joint debugging. During debugging, the diversion company is the request sender, and by sending a task request to the request receiver, the request receiver performs the corresponding operation and returns the result. In an embodiment of the present application, the mock debugging module is arranged between the request sender and the request receiver, so that the mock debugging module can intercept the task request sent by the request sender to the request receiver and execute the task request.
[0058] S120: Determine whether the task request is a debugging request. If the task request is a debugging request, match a corresponding target mock object from a preset mock object set according to the debugging request.
[0059] Among them, a debugging request refers to a request initiated by the request sender to the request receiver for debugging one or more API interfaces. The mock object set includes multiple preset mock objects, each mock object simulates an API interface of the request receiver to implement the corresponding function. Specifically, the mock object set includes a storage module, which is used to save mock objects. The mock object is used to simulate the function of the API interface, thereby realizing the function of debugging in the mock object without actually calling the API interface of the request receiver. Before calling the API interface of the request receiver, it is first necessary to determine whether the task request is a debugging request, because the mock object is only used to perform debugging, so the mock object will be matched only when the task request is a debugging request. When it is determined that the task request is a debugging request, the mock object corresponding to the API interface that originally needs to be debugged will be selected to execute the debugging request based on the API interface that the debugging request originally needs to debug.
[0060] To determine whether a task request is a debugging request, you can pre-enter test account information. Using a real user account for debugging could potentially affect the credit history of the user associated with that account. Therefore, setting up test account information in advance is necessary. If the task request is sent from a test account, it can be determined to be a debugging request. If the task request is sent from a real user, the API interface of the request recipient in the business process will be called normally to execute the corresponding function.
[0061] S130: Process the debugging request through the target mock object to obtain mock data.
[0062] Mocks are designed to address the difficulty of development and testing due to coupling between different units. The target mock object simulates the functionality of the API interface being debugged by the debug request and simulates the execution of the debug request within the mock object to obtain the corresponding mock data.
[0063] S140: Determine a debugging result according to the mock data.
[0064] The mock data is the result obtained after the target mock object processes the debugging request, and the debugging result is the debugging result of the API interface targeted by the debugging request determined based on the mock data. Since the target mock object is used to simulate the API interface, the debugging result can be obtained based on the mock data.
[0065] The technical solution provided by the embodiments of the present application, by setting up a mock debugging module between the request sender and the request receiver, executes the debugging request sent by the request sender through multiple mock objects included in the mock debugging module for simulating the API interface of the receiver, and returns the debugging results. The solution provided by the embodiments of the present application simulates the functions of the API interface through mock objects, so the debugging results can be obtained during debugging without actually calling the API interface, thereby improving debugging efficiency.
[0066] In this embodiment, optionally, determining a debugging result according to the mock data includes:
[0067] Determining target result comparison information corresponding to the request sender from a preset result comparison library; wherein the result comparison library includes at least one request sender and result comparison information corresponding to the request sender, and each type of result comparison information includes a correspondence between at least one debugging result and mock data;
[0068] The debugging result is determined according to the target result comparison information and the mock data.
[0069] To prevent debugging results from interfering with each other, data isolation is implemented for different debugging tasks, with different mock data corresponding to different request senders. For example, the result comparison information for request sender A is: mock data 123456 corresponds to successful debugging, while the result comparison information for request sender B is: mock data 654321 corresponds to successful debugging. Even if request senders A and B use the same mock object for debugging and both receive a successful debugging result, the mock data sent to request senders A and B will be different, namely, 123456 and 654321, respectively.
[0070] In the embodiment of the present application, different result comparison information is set for different data requesting parties, so that the mock data returned by the mock object to it can only obtain the corresponding debugging results through the corresponding result comparison information, thereby achieving the effect of data isolation and avoiding interference between multiple debugging parties.
[0071] Example 2
[0072] Figure 2This is a flowchart of the mock debugging method in Example 2 of the present invention. This example is optimized based on the above example. Specifically, each mock object is configured as follows: the target API interface corresponding to the current mock object is determined; based on the functionality of the target API interface, a custom function that can return mock data is obtained; and the custom function is filled into a blank object template to obtain the filled current mock object.
[0073] like Figure 2 As shown, the method of this embodiment specifically includes the following steps:
[0074] S210, determining the target API interface corresponding to the current mock object.
[0075] Each mock object corresponds to an API interface, and each mock object is used to implement the functions of its corresponding API. Therefore, when setting up a mock object, first determine the target API interface corresponding to the mock object, and then make specific settings based on the functions it implements.
[0076] S220: Obtain a custom function capable of returning mock data according to the function of the target API interface.
[0077] Among them, the custom function is the execution part of the mock object, which is used to execute the functions of the target API interface and return the corresponding mock data. Custom functions can use mock to develop general custom function functions and implement dynamic compilation and dynamic loading processes of custom functions. Specifically, based on the logic of the target API interface, write the source code (such as Java code) of the custom function that can simulate the mock data of the target API.
[0078] In addition, a custom function management module can be set up to manage the custom functions that have been written. The custom function management module can be used to search for custom functions and call the found custom functions. Optionally, this embodiment can obtain the function name and parameters of the custom function in the custom function management module, and then set the API interface corresponding to the custom function based on the obtained function name and parameters. In this way, when the mock object needs to generate mock data based on the custom function, the custom function can be called based on the custom function's API interface.
[0079] S230, filling the custom function into the blank object template to obtain the filled current mock object.
[0080] Among them, the blank object template is filled according to the functions to be implemented by the current mock object and the custom function. For example, if the function to be implemented is registration, the custom function used to implement the registration function is filled into the blank object template, and the corresponding registered mock object is obtained after filling.
[0081] Based on the above embodiments, Figure 3 This is a flowchart of a mock object setting method provided in the second embodiment of the present invention. Based on the above embodiments, optionally, after obtaining a custom function capable of returning mock data according to the function of the target API interface, the method further includes: determining whether there is an associated API interface having a mutually dependent coupling relationship with the target API interface; if so, obtaining a corresponding coupling function according to the function of the associated API interface; and integrating the coupling function into the custom function.
[0082] like Figure 3 As shown, the specific implementation steps of this embodiment include:
[0083] S310, determining the target API interface corresponding to the current mock object.
[0084] S320: Obtain a custom function capable of returning mock data according to the function of the target API interface.
[0085] S330: Determine whether there is an associated API interface that has a mutually dependent coupling relationship with the target API interface. If so, obtain a corresponding coupling function based on the function of the associated API interface.
[0086] Among them, the implementation of some API interface functions can only be achieved through the associated API interfaces that have a mutually dependent coupling relationship with them. If the target has a dependency on another API interface, it is necessary to simulate these dependent interfaces through mocks and verify the behavior of the called dependencies. For example, API interface A needs to be debugged. Interface A has three dependent API interfaces. If it is debugged through the actual API interface, all API interfaces need to be mobilized, which takes a long time. Therefore, according to the functions of the associated API interfaces, the corresponding coupling functions are obtained. The coupling functions are used to implement the functions of the associated API interfaces. By implementing these functions through mocks, there is no need to mobilize the associated API interfaces. All required API interfaces can be simulated only through mock objects.
[0087] S340: Integrate the coupling function into the custom function.
[0088] Among them, the coupling function is used to implement the functions of the associated API interface. By integrating the coupling function into the custom function used to implement the functions of the target API interface, the mock object can simulate multiple API interfaces through the integrated custom function, which can enable more efficient debugging.
[0089] S350, filling the custom function into the blank object template to obtain the filled current mock object.
[0090] Through such a setting, this solution integrates the coupling function of the associated API interface into the custom function, so that the mock object can execute the functions of the target API interface and the associated API interface that has a coupling relationship with the target API interface, thereby eliminating the need to call multiple API interfaces for debugging and further improving debugging efficiency.
[0091] Example 3
[0092] Figure 4 This is a flowchart of the mock data acquisition method in Example 3 of the present invention. This example is optimized based on the above example. Specifically, the optimization includes: the debug request includes debug parameter values; the debug request is processed by the target mock object to obtain mock data, including: calling the target custom function of the target mock object based on the debug parameter values; obtaining the return value of the target custom function; and filling a preset data template with the return value to obtain the filled mock data.
[0093] like Figure 4 As shown, the specific implementation steps of this embodiment include:
[0094] S410: Calling a target custom function of the target mock object according to the debugging parameter value.
[0095] Debug parameter values are parameters required during debugging. For example, if the debugging request involves account registration, the debug parameter value includes the account and password used to register the application and perform debugging. Based on the debug parameter value, the target custom function is called, allowing the custom function to perform operations using the debug parameter value.
[0096] S420: Obtain the return value of the target custom function.
[0097] When the target user-defined function is called through the debugging parameter value for operation, the target user-defined function will obtain the return value based on the debugging parameter value.
[0098] S430: Fill a preset data template with the return value to obtain filled mock data.
[0099] If the data template includes information about the target custom function, the data template can be populated based on the target custom function's return value to generate mock data. If the data template includes information about the target custom function and at least some fields in a debug request, the data template can be populated based on the target custom function's return value and at least some fields in the debug request to generate mock data. For example, if the mock data acquisition request is a registration request, the data template can be determined based on the registration request, and the target custom function in the data template can be called to complete the registration operation and return a result. The data template can then be populated based on the result returned by the target custom function to generate mock data.
[0100] Based on the above embodiments, the mock debugging method further includes: if it is detected that at least one API interface of the request recipient generates an update event, determining the mock object to be updated corresponding to the updated API interface; and updating the mock object according to the function of the updated API interface.
[0101] An update event indicates that the functionality of an API interface has changed, so the corresponding mock object simulating the API interface also needs to be updated. A pre-configured synchronization module can be used to modify the mock object later, allowing it to be updated instantly as the corresponding API interface is updated. If the mock object is not updated, the API interface cannot be simulated. By updating the mock object instantly, the API interface can be better simulated.
[0102] Example 4
[0103] Figure 5 This is a flowchart of a method for determining a task request provided in Example 4 of the present invention. This example is optimized based on the above example. The specific optimization steps include: determining the user information included in the task request; determining whether the user information is included in a preset debugging user information library; wherein the debugging user information library includes at least one user information for debugging; if the debugging user information library includes the user information, determining that the task request is a debugging request; and if the debugging user information library does not include the user information, calling the API interface corresponding to the request recipient to process the task request.
[0104] like Figure 5 As shown, the specific implementation steps of this embodiment include:
[0105] S510: Determine user information included in the task request.
[0106] S520: Determine whether the preset debugging user information library includes the user information; wherein the debugging user information library includes at least one user information for debugging.
[0107] Whether a task request is a debugging request can be determined by pre-entering the user information used for debugging. If a real user account is used for debugging, the account may affect the personal credit of the user corresponding to the account. Therefore, it is necessary to set up simulated user information used only for debugging in advance and save it in the debugging user information library. Whether the task request is a debugging request is determined based on the debugging user information library.
[0108] S530: If the debugging user information library includes the user information, determine that the task request is a debugging request; if the debugging user information library does not include the user information, call the API interface corresponding to the request receiver to process the task request.
[0109] If the task request is sent by user information, it can be determined that the task request is a debugging request. If the task request is sent by a real user, that is, the debugging user information database does not include the user information, then the API interface of the request recipient in the business process is called normally to execute the corresponding function normally.
[0110] Example 5
[0111] Figure 6 This is a block diagram of the mock debugging device provided in the fifth embodiment of the present invention. The device can execute the mock debugging method provided in any embodiment of the present invention and has the corresponding functional modules and beneficial effects of the execution method. The mock debugging module is set between the request sender and the request receiver. Figure 6 As shown, the device may include:
[0112] The task receiving unit 610 is configured to receive the task request from the request sender;
[0113] The debugging request determining unit 620 is configured to determine whether the task request is a debugging request;
[0114] A mock object matching unit 630 is configured to match a corresponding target mock object from a preset mock object set according to the debugging request when the task request is a debugging request, wherein each mock object is used to simulate an API interface of the request recipient;
[0115] A mock data acquisition unit 640 is configured to process the debugging request through the target mock object to obtain mock data;
[0116] The debugging result determination unit 650 is configured to determine the debugging result according to the mock data. The above product can execute the mock debugging method provided in the embodiment of the present application, and has the corresponding functional modules and beneficial effects of the execution method.
[0117] In an embodiment of the present application, the debugging request judgment unit 620 is used to determine the user information included in the task request; determine whether the preset debugging user information library includes the user information; wherein the debugging user information library includes at least one user information for debugging; if the debugging user information library includes the user information, then determine that the task request is a debugging request; if the debugging user information library does not include the user information, then call the API interface corresponding to the request recipient to process the task request.
[0118] In the embodiments of this application, Figure 7 As shown, the apparatus further includes: a mock object setting unit 710;
[0119] The mock object setting unit 710 is used to determine the target API interface corresponding to the current mock object; obtain a custom function that can return mock data based on the function of the target API interface; fill the custom function into the blank object template to obtain the filled current mock object.
[0120] In an embodiment of the present application, the mock object setting unit 710, after executing the custom function that can return mock data according to the function of the target API interface, is further used to execute: determining whether there is an associated API interface that has a mutually dependent coupling relationship with the target API interface; if so, obtaining a corresponding coupling function according to the function of the associated API interface; and integrating the coupling function into the custom function.
[0121] In an embodiment of the present application, the debugging request includes a debugging parameter value;
[0122] The mock data acquisition unit 640 is used to call the target custom function of the target mock object according to the debugging parameter value; obtain the return value of the target custom function; fill the preset data template with the return value to obtain the filled mock data.
[0123] In an embodiment of the present application, the debugging result determination unit 650 is configured to determine target result comparison information corresponding to the request sender from a preset result comparison library; wherein the result comparison library includes at least one request sender and result comparison information corresponding to the request sender, and each type of result comparison information includes a correspondence between at least one debugging result and mock data; and the debugging result is determined based on the target result comparison information and the mock data.
[0124] In the embodiments of this application, Figure 7As shown, the device further includes: a mock object updating unit 720.
[0125] The mock object updating unit 720 is configured to determine the mock object to be updated corresponding to the updated API interface if it is detected that at least one API interface of the request recipient has generated an update event; and update the mock object according to the function of the updated API interface.
[0126] Example 6
[0127] Embodiment 6 of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the mock debugging method provided in all embodiments of the present invention is implemented as follows:
[0128] receiving a task request from the request sender;
[0129] Determining whether the task request is a debugging request;
[0130] If the task request is a debugging request, matching a corresponding target mock object from a preset mock object set according to the debugging request; wherein each mock object is used to simulate an API interface of the request recipient;
[0131] Processing the debugging request through the target mock object to obtain mock data;
[0132] A debugging result is determined according to the mock data.
[0133] Any combination of one or more computer-readable media can be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device or device.
[0134] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0135] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0136] Computer program code for performing the operations of the present invention may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0137] Example 7
[0138] Embodiment 7 of the present application provides an electronic device. Figure 8 This is a schematic diagram of the structure of an electronic device provided in Example 6 of this application. Figure 8 As shown, this embodiment provides an electronic device 800, which includes: one or more processors 820; a storage device 810 for storing one or more programs. When the one or more programs are executed by the one or more processors 820, the one or more processors 820 implement the mock debugging method provided in the embodiment of the present application. The method includes:
[0139] receiving a task request from the request sender;
[0140] Determining whether the task request is a debugging request;
[0141] If the task request is a debugging request, matching a corresponding target mock object from a preset mock object set according to the debugging request; wherein each mock object is used to simulate an API interface of the request recipient;
[0142] Processing the debugging request through the target mock object to obtain mock data;
[0143] A debugging result is determined according to the mock data.
[0144] Of course, those skilled in the art will appreciate that the processor 820 also implements the technical solution of the mock debugging method provided in any embodiment of the present application.
[0145] Figure 8 The electronic device 800 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.
[0146] like Figure 8 As shown, the electronic device 800 includes a processor 820, a storage device 810, an input device 830, and an output device 840; the number of processors 820 in the electronic device can be one or more. Figure 8 In the figure, a processor 820 is used as an example; the processor 820, the storage device 810, the input device 830 and the output device 840 in the electronic device can be connected via a bus or other means. Figure 8 The connection via bus 850 is taken as an example.
[0147] The storage device 810 is a computer-readable storage medium that can be used to store software programs, computer executable programs, and module units, such as program instructions corresponding to the mock debugging method in the embodiment of the present application.
[0148] The storage device 810 may primarily include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function; the data storage area may store data created based on the use of the terminal, etc. Furthermore, the storage device 810 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state memory device. In some instances, the storage device 810 may further include memory remotely located relative to the processor 820, and such remote memory may be connected via a network. Examples of such networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0149] The input device 830 may be used to receive input numbers, character information or voice information, and generate key signal input related to user settings and function control of the electronic device. The output device 840 may include electronic devices such as a display screen and a speaker.
[0150] The mock debugging apparatus, medium, and electronic device provided in the above embodiments can execute the mock debugging method provided in any embodiment of the present application, and have the corresponding functional modules and beneficial effects of executing the method. For technical details not fully described in the above embodiments, please refer to the mock debugging method provided in any embodiment of the present application.
[0151] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the concept of the present invention. The scope of the present invention is determined by the scope of the appended claims.
Claims
1. A mock debugging method, characterized in that: The method is performed by a mock debugging module, which is arranged between a request sender and a request receiver. The method includes: receiving a task request from the request sender; Determining whether the task request is a debugging request; If the task request is a debugging request, matching a corresponding target mock object from a preset mock object set according to the debugging request; wherein each mock object is used to simulate an API interface of the request recipient; Processing the debugging request through the target mock object to obtain mock data; Determine the debugging result according to the mock data; Each of the mock objects is set up as follows: Determine the target API interface corresponding to the current mock object; According to the function of the target API interface, obtain a custom function that can return mock data; Fill the custom function into the blank object template to obtain the filled current mock object; After obtaining a custom function capable of returning mock data according to the function of the target API interface, the method further includes: Determine whether there is an associated API interface that has a mutually dependent coupling relationship with the target API interface; If it exists, obtain the corresponding coupling function according to the function of the associated API interface; Integrate the coupling function into the custom function.
2. The method according to claim 1, characterized in that Determining whether the task request is a debugging request includes: Determining user information included in the task request; Determine whether the preset debugging user information library includes the user information; wherein the debugging user information library includes at least one user information for debugging; If the debugging user information library includes the user information, the task request is determined to be a debugging request; if the debugging user information library does not include the user information, the API interface corresponding to the request receiver is called to process the task request.
3. The method according to claim 1, characterized in that The debugging request includes a debugging parameter value; Processing the debugging request through the target mock object to obtain mock data includes: Call the target custom function of the target mock object according to the debugging parameter value; Obtain the return value of the target custom function; The preset data template is filled with the return value to obtain the filled mock data.
4. The method according to claim 1, wherein Determine the debugging result according to the mock data, including: Determining target result comparison information corresponding to the request sender from a preset result comparison library; wherein the result comparison library includes at least one request sender and result comparison information corresponding to the request sender, and each type of result comparison information includes a correspondence between at least one debugging result and mock data; The debugging result is determined according to the target result comparison information and the mock data.
5. The method according to claim 1, wherein The method further comprises: If it is detected that at least one API interface of the request recipient has generated an update event, determine the mock object to be updated corresponding to the updated API interface; Update the mock object according to the function of the update API interface.
6. A mock debugging device, characterized in that: The mock debugging device is provided between the request sender and the request receiver, and includes: A task receiving unit, configured to receive a task request from the request sender; a debugging request judging unit, configured to determine whether the task request is a debugging request; A mock object matching unit is configured to match a corresponding target mock object from a preset mock object set according to the debugging request when the task request is a debugging request, wherein each mock object is used to simulate an API interface of the request recipient; A mock data acquisition unit, configured to process the debugging request through the target mock object to obtain mock data; A debugging result determining unit, configured to determine a debugging result based on the mock data; The mock debugging device further includes: a mock object setting unit; The mock object setting unit is used to determine the target API interface corresponding to the current mock object; obtain a custom function that can return mock data based on the function of the target API interface; fill the custom function into the blank object template to obtain the filled current mock object; The mock object setting unit, after executing the function of the target API interface to obtain a custom function capable of returning mock data, is further used to execute: Determine whether there is an associated API interface that has a mutually dependent coupling relationship with the target API interface; if so, obtain a corresponding coupling function based on the function of the associated API interface; and integrate the coupling function into the custom function.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the mock debugging method according to any one of claims 1 to 5 is implemented.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein: When the processor executes the computer program, the mock debugging method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Service test method, device and system, storage medium and electronic device
CN112732572A
Mock data generation method and device
CN113342353A