CN115904949A - Interface simulation method, device, equipment and storage medium - Google Patents

Interface simulation method, device, equipment and storage medium Download PDF

Info

Publication number
CN115904949A
CN115904949A CN202211379664.4A CN202211379664A CN115904949A CN 115904949 A CN115904949 A CN 115904949A CN 202211379664 A CN202211379664 A CN 202211379664A CN 115904949 A CN115904949 A CN 115904949A
Authority
CN
China
Prior art keywords
interface
simulated
simulation
application
called
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211379664.4A
Other languages
Chinese (zh)
Inventor
胡鹏强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China United Network Communications Group Co Ltd
Original Assignee
China United Network Communications Group Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China United Network Communications Group Co Ltd filed Critical China United Network Communications Group Co Ltd
Priority to CN202211379664.4A priority Critical patent/CN115904949A/en
Publication of CN115904949A publication Critical patent/CN115904949A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The disclosure provides an interface simulation method, an interface simulation device, interface simulation equipment and a storage medium, which relate to the technical field of computers and can acquire interface information of a target interface and at least one interface response configuration item through a monitoring instruction when an application to be simulated is started so as to realize monitoring and simulation of the target interface and improve the testing efficiency. The method comprises the following steps: receiving a starting request of an application to be simulated, wherein the starting request carries a monitoring instruction; starting the application to be simulated based on the starting request, and acquiring interface information of a target interface and at least one interface response configuration item based on the monitoring instruction; judging whether an invoked target interface exists in the started application to be simulated or not based on the interface information; responding to the started application to be simulated to have the called target interface, and simulating the called target interface based on the at least one interface response configuration item.

Description

Interface simulation method, device, equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to an interface simulation method, apparatus, device, and storage medium.
Background
In daily test work, it is often necessary to simulate (mock) certain interfaces or methods to return some specified response or result in order for the business process to continue normally. For different application scenarios, there are several technical solutions for simulation application. Firstly, for an interface initiated to be called from a client, a proxy server can be added between the client and an application server, and the response content of the interface is directly simulated in the proxy server, so that an interface request cannot be sent to the application server, and the simulation of the interface is realized; secondly, for interface calling between application servers, response return values of the interfaces can be written down by developers in a code modifying mode without actually executing code logic of the interfaces so as to realize simulation of the interfaces; thirdly, for the interface call between the application servers, a service monitoring tool can be used to monitor the execution of the interface, and when the interface is called, the real response content of the interface is replaced by the fixed response content, so as to realize the simulation of the interface.
Because a fixed simulation response value is returned every time the interface is called in the test process, if the simulation response value needs to be changed, the response content needs to be modified, and then the test is carried out. If in a complex business process needing to call the same interface for multiple times and needing to return different responses each time when the interface is called, or two testers respectively carry out two business processes in two different test scenes, the same interface needs to be called simultaneously, and different response values need to be returned to the two testers after the interface is called, then the testers can only repeatedly carry out multiple test works, and the response values of the interface are modified before each test work, thereby greatly reducing the test efficiency.
Disclosure of Invention
The disclosure provides an interface simulation method, device, equipment and storage medium, which are used for improving test efficiency.
In order to achieve the purpose, the technical scheme is as follows:
in a first aspect, a method for interface simulation is provided, where the method includes:
receiving a starting request of an application to be simulated, wherein the starting request carries a monitoring instruction;
starting the application to be simulated based on the starting request, and acquiring interface information of a target interface and at least one interface response configuration item based on the monitoring instruction;
judging whether an invoked target interface exists in the started application to be simulated or not based on the interface information;
responding to the started application to be simulated to have the called target interface, and simulating the called target interface based on the at least one interface response configuration item.
With reference to the first aspect, in a possible implementation manner, the determining, based on the interface information, whether an invoked target interface exists in the started application to be simulated, includes:
acquiring a called interface and interface information in the started application to be simulated;
and when the interface information of the target interface to be monitored has the same interface information as the called interface, judging that the called target interface exists in the application to be simulated.
With reference to the foregoing first aspect, in a possible implementation manner, the interface response configuration item includes: simulating an input parameter value, a simulated response value and the residual cycle number;
the simulating the called target interface based on the at least one interface response configuration item comprises:
acquiring an actual input parameter value corresponding to the called target interface, and judging whether each field in the simulated input parameter value is included in the actual input parameter value;
responding to each field in the actual input parameter value, wherein each field comprises the simulated input parameter value, and judging whether the residual cycle number is zero or not;
and if the residual cycle number is not zero, reducing the residual cycle number by one, and sending the simulation response value to a calling end for calling the called target interface.
With reference to the first aspect, in a possible implementation manner, before obtaining the interface information of the target interface and the at least one interface response configuration item based on the monitoring instruction, the method further includes:
the method comprises the steps of obtaining a configuration instruction sent by a user, and determining interface information of a target interface needing to be monitored and at least one interface response configuration item based on the configuration instruction.
In a second aspect, an interface simulation apparatus is provided, the apparatus comprising:
the device comprises a request receiving module, a monitoring module and a simulation module, wherein the request receiving module is used for receiving a starting request of an application to be simulated, and the starting request carries a monitoring instruction;
the request processing module is used for starting the application to be simulated based on the starting request and acquiring interface information of a target interface and at least one interface response configuration item based on the monitoring instruction;
the interface calling monitoring module is used for judging whether a called target interface exists in the started application to be simulated or not based on the interface information;
and the interface simulation module is used for responding to the existence of the called target interface in the started application to be simulated and simulating the called target interface based on the at least one interface response configuration item.
With reference to the second aspect, in a possible implementation manner, the interface call monitoring module includes:
the interface information acquisition unit is used for acquiring the called interface and the interface information in the started application to be simulated;
and the target interface determining unit is used for judging that the called target interface exists in the application to be simulated when the interface information of the target interface to be monitored has the same interface information as the called interface.
With reference to the second aspect, in a possible implementation manner, the interface response configuration item includes: simulating an input parameter value, a simulated response value and the residual cycle number;
the interface simulation module comprises:
the parameter input value judging unit is used for acquiring an actual parameter input value corresponding to the called target interface and judging whether each field in the simulated parameter input value is included in the actual parameter input value;
a residual cycle number judging unit, configured to respond to each field in the actual input parameter value that includes the simulated input parameter value, and judge whether the residual cycle number is zero;
and the simulation response unit is used for reducing the residual cycle number by one if the residual cycle number is not zero, and sending the simulation response value to a calling end for calling the called target interface.
With reference to the second aspect, in a possible implementation manner, the apparatus further includes:
and the configuration instruction acquisition module is used for acquiring a configuration instruction sent by a user and determining interface information of a target interface to be monitored and at least one interface response configuration item based on the configuration instruction.
In a third aspect, an interface emulation device is provided, comprising: a processor and a memory; wherein the memory is configured to store computer-executable instructions, and when the interface simulation apparatus is running, the processor executes the computer-executable instructions stored by the memory to cause the interface simulation apparatus to perform the interface simulation method as described in the first aspect and any one of the possible implementations of the first aspect.
In a fourth aspect, the present disclosure provides a computer-readable storage medium having instructions stored therein, which when executed by a processor of an interface simulation device, enable the interface simulation device to perform the interface simulation method as described in the first aspect and any one of the possible implementations of the first aspect.
In the present disclosure, the names of the above-mentioned interface simulation devices do not limit the devices or functional modules themselves, and in actual implementation, these devices or functional modules may appear by other names. Insofar as the functions of the respective devices or functional modules are similar to those of the present disclosure, they are within the scope of the claims of the present disclosure and their equivalents.
These and other aspects of the disclosure will be more readily apparent from the following description.
The technical scheme provided by the disclosure at least brings the following beneficial effects: the present disclosure provides an interface simulation method, apparatus, device and storage medium, the method comprising: receiving a starting request of an application to be simulated, wherein the starting request carries a monitoring instruction; starting the application to be simulated based on the starting request, and acquiring interface information of a target interface and at least one interface response configuration item based on the monitoring instruction; judging whether an invoked target interface exists in the started application to be simulated or not based on the interface information; responding to the started application to be simulated to have the called target interface, and simulating the called target interface based on the at least one interface response configuration item. The user can configure the interface information of the target interface and at least one interface response configuration item, namely, the monitoring and simulation of a plurality of target interfaces can be realized through configuration operation, and different simulations of the same target interface can also be realized by setting a plurality of interface response configuration items, so that the test efficiency is improved.
Drawings
Fig. 1 is a schematic diagram of a hardware structure of an interface simulation apparatus provided in the present disclosure;
fig. 2 is a schematic flow chart of an interface simulation method according to the present disclosure;
fig. 3 is a schematic view of an operation interface display in an interface simulation method according to the present disclosure;
FIG. 4 is a schematic view of an operation interface display in another interface simulation method provided by the present disclosure;
FIG. 5 is a schematic view of an operation interface display in another interface simulation method provided by the present disclosure;
FIG. 6 is a schematic flow chart diagram illustrating another interface simulation method provided by the present disclosure;
FIG. 7 is a schematic flow chart diagram illustrating another interface simulation method provided by the present disclosure;
fig. 8 is a schematic structural diagram of an interface simulation apparatus provided in the present disclosure.
Detailed Description
The interface simulation method, apparatus, device and storage medium provided in the embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
The terms "first" and "second" and the like in the specification and drawings of the present disclosure are used for distinguishing different objects or for distinguishing different processes for the same object, and are not used for describing a specific order of the objects.
Furthermore, the terms "including" and "having," and any variations thereof, as referred to in the description of the present disclosure, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It is noted that in the embodiments of the present disclosure, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "e.g.," in an embodiment of the present disclosure is not to be construed as preferred or advantageous over other embodiments or designs. Rather, use of the word "exemplary" or "such as" is intended to present relevant concepts in a concrete fashion.
Fig. 1 is a schematic structural diagram of an interface simulation device according to an embodiment of the present disclosure. As shown in fig. 1, the interface simulation apparatus 100 includes at least one processor 101, a communication line 102, and at least one communication interface 104, and may further include a memory 103. The processor 101, the memory 103 and the communication interface 104 may be connected via a communication line 102.
The processor 101 may be a Central Processing Unit (CPU), an Application Specific Integrated Circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present disclosure, such as: one or more Digital Signal Processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs).
The communication link 102 may include a path for communicating information between the aforementioned components.
The communication interface 104, which is used for communicating with other devices or a communication network, may use any transceiver or other devices, such as ethernet, radio Access Network (RAN), wireless Local Area Network (WLAN), etc.
The memory 103 may be, but is not limited to, a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a Random Access Memory (RAM) or other type of dynamic storage device that can store information and instructions, an electrically erasable programmable read-only memory (EEPROM), a compact disk read-only memory (CD-ROM) or other optical disk storage, optical disk storage (including compact disk, laser disk, optical disk, digital versatile disk, blu-ray disk, etc.), magnetic disk storage or other magnetic storage devices, or any other medium that can be used to contain or store desired program code in the form of instructions or data structures and that can be accessed by a computer.
In a possible design, the memory 103 may exist separately from the processor 101, that is, the memory 103 may be a memory external to the processor 101, in which case, the memory 103 may be connected to the processor 101 through the communication line 102, and is used for storing execution instructions or application program codes, and is controlled by the processor 101 to execute, so as to implement the network quality determination method provided by the following embodiments of the present disclosure. In yet another possible design, the memory 103 may also be integrated with the processor 101, that is, the memory 103 may be an internal memory of the processor 101, for example, the memory 103 is a cache memory, and may be used for temporarily storing some data and instruction information.
As one implementation, processor 101 may include one or more CPUs, such as CPU0 and CPU1 in fig. 1. As another implementation, the interface simulation device 100 may include multiple processors, such as the processor 101 and the processor 107 of FIG. 1. As yet another implementation, the interface simulation device 100 may also include an output device 105 and an input device 106.
Through the description of the above embodiments, it is clear to those skilled in the art that, for convenience and simplicity of description, the foregoing division of the functional modules is merely used as an example, and in practical applications, the foregoing function distribution may be completed by different functional modules according to needs, that is, the internal structure of the network node is divided into different functional modules to complete all or part of the above described functions. For the specific working processes of the system, the module and the network node described above, reference may be made to the corresponding processes in the foregoing method embodiments, which are not described herein again.
Hereinafter, terms related to the present application will be explained.
1. JVM (Java Virtual Machine):
the specification is used for computing equipment, is a fictitious computer and is realized by simulating various computer functions on an actual computer.
2. Sandbox (Chinese name: sandbox):
the method is an AOP (Aspect Oriented Programming) solution framework, and can perform related operations on the program in the JVM process on the premise of not restarting and not intruding into the target JVM application. The section-oriented programming is a technology for realizing the unified maintenance of the program functions through a pre-compiling mode and a dynamic proxy during running.
In daily test work, it is often necessary to simulate (mock) certain interfaces or methods to return some specified response or result in order for the business process to continue normally. In the current test process, each time the interface is called, a fixed simulated response value is returned, and if the simulated response value needs to be changed, the response content needs to be modified again before the next test.
In a business process in a certain business scene, after a user logs in a page, an inquiry interface needs to be called once to inquire whether the user accords with the getting qualification, if the user accords with the getting qualification, the types of prizes which can be got by the user are displayed on the page, and the user clicks the getting after selecting a certain prize on the page. The method comprises the steps that a user clicks the getting operation to trigger calling of a getting interface, when the getting interface is called to execute the getting logic, a query interface is called inside the getting interface to query whether the user gets the prize in the current month, and if the user does not get the prize, the user can get the prize successfully. And after the successful picking, the interface returns to the page with the successful picking, and at the moment, the page can be automatically refreshed and the inquiry interface is requested again to obtain the prize information picked by the user and display the prize information on the page. The whole business process is uninterruptable and continuously operated, and in the process, the query interface is called for 3 times, and different response contents are returned every time.
For the above service scenario, the interface simulation in the prior art can only return a fixed value, and therefore it cannot be guaranteed that the continuous service flow can complete the simulation of all interfaces in one test process.
In order to solve the technical problem, the application provides an interface simulation method, which receives a starting request of an application to be simulated, wherein the starting request carries a monitoring instruction; starting the application to be simulated based on the starting request, and acquiring interface information of a target interface and at least one interface response configuration item based on the monitoring instruction; judging whether an invoked target interface exists in the started application to be simulated or not based on the interface information; responding to the started application to be simulated to have the called target interface, and simulating the called target interface based on the at least one interface response configuration item. The method comprises the steps that a starting request is received, an application to be simulated can be started, meanwhile, interface information of a target interface and at least one interface response configuration item can be obtained based on a monitoring instruction in the starting request, and therefore whether the called target interface exists in the started application to be simulated or not can be judged according to the interface information of the target interface, and the interface in the application to be simulated is monitored. And when the called target interface exists in the application to be simulated, continuing to simulate the called interface based on the at least one interface response configuration item. Therefore, a user can configure the interface information of the target interface and at least one interface response configuration item, namely, monitoring and simulation of a plurality of target interfaces can be realized through one-time operation, and different simulations of the same target interface can also be realized by setting a plurality of interface response configuration items.
Fig. 2 is a schematic flowchart of an interface simulation method provided by the present disclosure, where the interface simulation method may be specifically implemented by the following steps (S210-S240):
step S210: receiving a starting request of an application to be simulated, wherein the starting request carries a monitoring instruction.
When a user sends a starting request carrying a monitoring instruction to an application to be simulated, the starting request can be sent in the following modes.
In the first way, a user may initiate a request for starting the application to be simulated through the graphical display interactive interface, and add a monitoring instruction to the start request, for example, a start button and a monitoring option are included in a start page of the application to be simulated. Before the user clicks the start button, the monitoring options are selected to be in a selected state, and at the moment, the user clicks the start button on the started page, and then the start request carrying the monitoring instruction can be sent.
In the second mode, when the user sends a starting request carrying the monitoring instruction to the application to be simulated by entering a command in the command input box. For example, assuming that the application is a kcard-charge, the user types a command to launch the application as java-java agent:/root/. Sandbox-module/project b.
Step S220: and starting the application to be simulated based on the starting request, and acquiring interface information of a target interface and at least one interface response configuration item based on the monitoring instruction.
As an embodiment, before obtaining the interface information of the target interface and the at least one interface response configuration item based on the monitoring instruction, the method further includes:
the method comprises the steps of obtaining a configuration instruction sent by a user, and determining interface information of a target interface needing to be monitored and at least one interface response configuration item based on the configuration instruction.
The target interface is an interface which needs to be monitored and simulated, so that the interface information of the target interface and the at least one interface response configuration item which are acquired based on the monitoring instruction are preset. In an embodiment, the interface information of the target interface may be obtained in a cache database based on the monitoring instruction, where the cache database includes interface information configured by the user and needing to be monitored and simulated, and a corresponding interface response configuration item. The interface information and the corresponding interface response configuration items in the cache database are obtained according to the operation of the user, and the user can add, delete, modify and the like the interface information and the corresponding interface response configuration items in the cache database.
For example, referring to fig. 3, a tester may add interface information to be monitored and simulated through the display interface shown in fig. 3, where the interface information shown in the figure includes a service name, a package name, a class name, and a method name. After the user adds the interface information, the user clicks a 'monitor' button in the interface, and the service name, package name, class name and method name input by the user are saved in the cache database. That is, the user clicks the "monitor" button after filling in the interface information, i.e., the transmission of the first request is completed.
After clicking a "monitoring" key in the interface by a user, then displaying an interface as shown in fig. 4, where the interface includes interface information that has been input and stored by the user and corresponding operation keys, the user may perform corresponding interface response configuration item configuration operation on the input and stored interface information by clicking a "configuration simulation" key in the interface, and after clicking a "configuration simulation" key in the interface by the user, displaying the interface as shown in fig. 5, and the user may input editing and deleting operations of simulation input parameters, simulation response values, and remaining cycle times in the interface. If the user does not need to simulate the response of the input and stored interface information, the user can delete the input and stored interface information by clicking a delete key in the interface.
Step S230: and judging whether an invoked target interface exists in the started application to be simulated or not based on the interface information.
In some embodiments, the step S230 of determining whether there is an invoked target interface in the started application to be simulated based on the interface information includes the following steps (S231-S232), please refer to fig. 6:
step S231: acquiring a called interface and interface information in the started application to be simulated;
step S232: and when the interface information of the target interface to be monitored has the same interface information as the called interface, judging that the called target interface exists in the application to be simulated.
When judging whether the called target interface exists in the started application to be simulated or not based on the interface information, the calling interface information of the called interface in the application to be simulated can be obtained first, and if the calling interface information is the same as the interface information of the target interface, the called target interface exists in the started application to be simulated. Illustratively, the interface information of the target interface may include a service name of kcad-Auth, a package name of kcad. If the called interface information in the application to be simulated includes a service name of Kcard-auth, a packet name of kcard.src.java.controller, a class name of Priority, and a method name of getLevel, it may be determined that the called interface is not a target interface.
Step S240: responding to the started application to be simulated to have the called target interface, and simulating the called target interface based on the at least one interface response configuration item.
The interface response configuration item comprises a simulation response value, and when the called target interface exists in the started application to be simulated, the response value can be returned to a calling end for calling the target interface according to the simulation response value, so that the simulation of the target interface is realized.
As one embodiment, the interface response configuration item includes: a simulated parameter value, a simulated response value and a residual cycle number. The simulating S240 the invoked target interface based on the at least one interface response configuration item includes the following steps (S241-S243), please refer to FIG. 7:
step S241: and acquiring an actual input parameter value corresponding to the called target interface, and judging whether each field in the simulated input parameter value is included in the actual input parameter value.
For example, if the emulated ingress parameters in the interface response configuration item include { "phone": 131XXXX3335"," channel ": st" }, and the actual ingress parameters corresponding to the invoked interface include { "phone": 131XXXX3335"," channel ": wx", "timestamp": 1662866446869"," usertype ": newUser" }, it can be seen that all fields in the emulated ingress parameters in the interface response configuration item are not included in the actual ingress parameters corresponding to the invoked interface; the simulated parameters in the interface response configuration item comprise { "phone": 131XXXX3335"}, and the actual parameters corresponding to the called interface comprise {" phone ": 131XXXX3335", "channel": wx "," timetag ": 1662866446869", "usertype": newUser "}, then it can be seen that the actual parameters corresponding to the called interface comprise all fields in the simulated parameters in the interface response configuration item; the simulated ingress parameters in the interface response configuration item include { "phone": 131XXXX3335"," channel ": wx", "usertype": newUser "}, and the actual ingress parameters corresponding to the called interface include {" phone ": 131XXXX3335", "channel": wx "}, then it can be seen that the actual ingress parameters corresponding to the called interface do not include all the fields in the simulated ingress parameters in the interface response configuration item.
As an embodiment, when determining whether each field in the simulated parameter is included in the actual parameter, the matching may be performed by using a regular expression, which is a logic formula operating on a character string, and a "rule character string" is formed by using some specific characters defined in advance and a combination of the specific characters, and is used to express a filtering logic for the character string.
Step S242: and responding to each field in the actual input parameter value, wherein the field comprises the simulated input parameter value, and judging whether the residual cycle number is zero or not.
Step S243: and if the residual cycle number is not zero, reducing the residual cycle number by one, and sending the simulation response value to a calling end for calling the called target interface.
As shown in fig. 5, the first row of data in fig. 5 is an interface response configuration item, in the interface response configuration item, the simulated entry parameter is { "phone": 131XXXX3335"}, the actual entry parameter is also {" phone ": 131XXXX3335" }, whether each field in the simulated entry parameter is included in the actual entry parameter or not, and the number of cycles in the interface response configuration item is 1, then the simulated response value may be sent to the calling end that calls the called interface, and the number of cycles 1 is changed to 0.
If the target interface has a plurality of interface response configuration items, as shown in fig. 5, one target interface corresponds to three rows of data, that is, three interface response configuration items. If the actual parameter values are { "phone": 131XXXX3335"," channel ": wx" }, all the interface response configuration items are traversed, first, the simulated parameter values in the first row of interface response configuration items are { "phone": 131XXXX3335", and it can be seen that each field in the simulated parameter values is not included in the actual parameter values. At this time, the simulated parameter values in the second row interface response configuration items are continuously read, and according to the actual parameter values { "phone": 131XXXX3335"," channel ": wx" } and the simulated parameter values { "phone": 131XXXX3335"," channel ": wx" } in the second row interface response configuration items, it can be seen that each field in the simulated parameter values is included in the actual parameter values, but the cycle number is 0 at this time. Then the simulated parameter values in the third row interface response configuration items are continuously read, and according to the actual parameter values { "phone": 131XXXX3335"," channel ": wx" } and the simulated parameter values in the third row { "phone": 131XXXX3335"," channel ": st" }, it can be seen that each field in the simulated parameter values is not included in the actual parameter values, so far, the traversal of all interface response configuration items is completed, and then the actual response values of the called interfaces are returned and are not simulated.
When a certain interface is called for many times in continuous and uninterruptible business process operation, the method can be used for monitoring and simulating each interface call, and when the called interface is a target interface, simulation processing of the target interface is realized by traversing interface response configuration items configured by a user. During the sequential traversal, if the actual entry parameter value in the call data corresponding to the called interface includes all fields in the simulated entry parameter value in the interface response configuration item configured by the user, and the cycle number in the interface response configuration item is greater than 0, the simulated response value in the interface response configuration item is returned as the simulation result of the interface. Therefore, by sequentially configuring a plurality of interface response configuration items and setting the cycle number in each interface response configuration item, the test requirement that the interface is continuously called for a plurality of times in a continuous and uninterruptible business process and each interface response needs to simulate different response values can be met.
The method can be realized by only distinguishing the input parameter values when the configuration interface responds to the configuration items, for the requirements that different testers call the same target interface in different service scenes and need to simulate and return corresponding response contents. For example, the tester A configures the interface response configuration item of a certain target interface M, and the tester B also configures the interface response configuration item of the target interface M, then the tester A sets the simulation input parameter value to { "phone": 131XXXX3335"}, and simultaneously the tester A sets the simulation response value to {" code ": 10000" }; the tester B sets the simulation input value as { "phone": 131XXX X3336"}, and simultaneously the tester B sets the simulation response value as {" code ": 40000" }, and the two testers can realize respective data simulation only by respectively using corresponding mobile phone numbers to carry out business process tests. The tester A calls the target interface M by using the mobile phone number 131XXXX3335, and the phone in the actual parameter values of the tester A when the interface is called is 131XXXX3335, so that the tester only receives the simulation response data { "code": 10000 "corresponding to {" phone ": 131XXXX 3335". In the same way, the tester B calls the target interface M by using the mobile phone number 131XXXX3336, and the phone in the actual parameter values of the tester B when calling the interface is 131XXXX3336, so that the tester only receives the simulation response data { "code": 40000 "corresponding to {" phone ": 131 XXXXX 3336" }.
As an implementation manner, when the interface simulation method is implemented, the start request carries a monitoring instruction, a dynamic tracking monitoring tool may be installed in the server to which the application to be simulated belongs, and the monitoring instruction may start the dynamic tracking monitoring tool, so that the dynamic tracking monitoring tool executes steps S220 to S240 in the interface simulation method. From the program execution perspective, the application being emulated is running in the environment of the JVM virtual machine after startup. And if the application to be simulated is provided with a dynamic tracking monitoring tool aiming at the JVM in the server to which the application to be simulated belongs, such as a JVM-sandbox (sandbox), the monitoring instruction carried in the starting request can enable the JVM-sandbox to load the monitoring simulation processing packet so as to obtain the processing logic in the monitoring simulation processing packet. Then, when the dynamic tracking monitoring tool executes the steps of S220-S240 in the interface simulation method, the processing logic of the step may be specifically packaged into a monitoring simulation processing packet, and the monitoring simulation processing packet is copied to the server to which the application to be simulated belongs, so that when the monitoring instruction is received, the monitoring instruction enables the dynamic tracking monitoring tool to start up, and the monitoring simulation processing packet is loaded to execute the processing logic in the monitoring simulation processing packet, thereby implementing the process in the interface simulation method.
For example, if the dynamic tracking monitoring tool installed in the server to which the application to be simulated belongs is jvm-sandb ox, the monitoring simulation processing package may be copied to the root/. Sandbox-mo directory of the server to which the application to be simulated belongs. The/root/. Sandbox-module is a sandbox system module directory, and is a general management module for storing sandboxes. The monitoring simulation processing package under the directory can be read and used by the jvm-sandbox, that is, as long as a monitoring option is added to the simulated application when the simulated application is started, the processing code in the monitoring simulation processing package can be started to monitor and simulate all interfaces of the application, that is, when the interfaces are executed, the monitoring logic in the monitoring simulation processing package core source code file interface monitor module.
It is understood that other tools with monitoring capability may be installed in the server to which the application to be simulated belongs, and besides the jvm-sandbox mentioned in the above example, dynamic tracking and monitoring tools such as btrace, remote-de bug-agent, etc. may also be installed in the server to which the application to be simulated belongs. Therefore, in the scheme of the present application, different dynamic tracking and monitoring tools can be used according to different situations, and the present application does not limit specific dynamic tracking and monitoring tools.
An acquisition process for monitoring the simulation process package is described below based on the above embodiment.
Illustratively, the processing logic in the monitoring processing package of the present application includes the following processes:
monitoring all interfaces in the application to be simulated, and entering a second step before executing an interface method corresponding to the calling operation when the interfaces are called.
Secondly, judging whether the interface method exists in the interface information of the target interface stored in the cache database, and if so, entering a third step; if not, the interface method is directly executed, so that the actual response value of the interface is returned.
Step three, judging whether an interface response configuration item corresponding to the interface method is stored in a cache database, and if so, entering the step four; if not, the interface method is directly executed.
And fourthly, reading an interface response configuration item corresponding to the interface method and stored in the cache database, and simulating according to the interface response configuration item and the calling data when the target interface is called.
If the interface response configuration items may include the simulation entry value, the simulation response value, and the remaining cycle number, in the fourth step, the following process may be performed on all the interface response configuration items by traversing, and separately performing the following process on each interface response configuration item:
the method comprises the following steps that firstly, the value of each field in the simulated parameter values in the interface response configuration item corresponding to a target interface is subjected to regular matching with the actual parameter contents in the interface method for calling the interface, and if the values are successfully matched, the next step is carried out; if the matching is not successful, no operation is carried out on the interface response configuration item, and the next interface response configuration item is continuously traversed.
Secondly, judging whether the residual cycle number in the interface response configuration item is 0, and if not, entering the next step; if the value is 0, no operation is performed on the interface response configuration item, and the next interface response configuration item is continuously traversed.
And thirdly, replacing the actual response content of the interface with the simulation response value in the interface response configuration item and returning the simulation response value to the caller, reducing the cycle number of the interface response configuration item by 1, and then ending the traversal of the interface response configuration item, namely not continuously traversing the next interface response configuration item.
When the monitoring simulation processing package is obtained through the processing logic, a code written based on the processing logic may be obtained first, a project is created through Java based on the code, and the project is compiled and packaged to generate an executable jar package, that is, the monitoring simulation processing package, for example, after the project is created based on the code, the executable jar package may be generated through a compiling and packaging command mvn install package.
Wherein, the project can be a spring project, and the jvm-sandbox executable related jar packages are integrated. In one embodiment, the core source code file of the project may be interface monitor module. The spring is a lightweight open-source framework.
After the monitoring simulation processing packet is obtained based on the processing logic packet, the monitoring simulation processing packet can be sent to the server to which the application to be simulated belongs. Specifically, the monitoring simulation processing package may be copied to a system directory of a server to which the application to be simulated belongs in a remote copy manner, and after receiving the monitoring instruction, the monitoring simulation processing package in the system directory may be loaded.
It can be seen that the technical solutions provided by the embodiments of the present disclosure are introduced mainly from the perspective of methods. To implement the above functions, it includes hardware structures and/or software modules for performing the respective functions. Those of skill in the art will readily appreciate that the various illustrative modules and algorithm steps described in connection with the embodiments disclosed herein may be implemented as hardware or combinations of hardware and computer software. Whether a function is performed as hardware or computer software drives hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present disclosure.
In the embodiment of the present application, the interface simulation apparatus may be divided into the functional modules or the functional units according to the method example, for example, each functional module or functional unit may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The integrated module may be implemented in a form of hardware, or may be implemented in a form of a software functional module or a functional unit. The division of the modules or units in the embodiment of the present application is schematic, and is only a logic function division, and there may be another division manner in actual implementation.
As shown in fig. 8, a schematic structural diagram of an interface simulation apparatus provided in an embodiment of the present application is shown, where the apparatus includes:
a request receiving module 810, configured to receive a start request of an application to be simulated, where the start request carries a monitoring instruction;
a request processing module 820, configured to start the application to be simulated based on the start request, and obtain interface information of a target interface and at least one interface response configuration item based on the monitoring instruction;
an interface call monitoring module 830, configured to determine whether there is a called target interface in the started application to be simulated based on the interface information;
the interface simulation module 840 is configured to, in response to that there is an invoked target interface in the started application to be simulated, simulate the invoked target interface based on the at least one interface response configuration item.
Optionally, the interface call monitoring module includes:
the interface information acquisition unit is used for acquiring the called interface and the interface information in the started application to be simulated;
and the target interface determining unit is used for judging that the called target interface exists in the application to be simulated when the interface information of the target interface to be monitored has the same interface information as the called interface.
Optionally, the interface response configuration item includes: simulating an input parameter value, a response value and the residual cycle number;
the interface simulation module comprises:
the parameter input value judging unit is used for acquiring an actual parameter input value corresponding to the called target interface and judging whether each field in the simulated parameter input value is included in the actual parameter input value;
a residual cycle number judging unit, configured to respond to each field in the actual input parameter value that includes the simulated input parameter value, and judge whether the residual cycle number is zero;
and the simulation response unit is used for reducing the residual cycle number by one if the residual cycle number is not zero, and sending the simulation response value to a calling end for calling the called target interface.
Optionally, the apparatus further comprises:
and the configuration instruction acquisition module is used for acquiring a configuration instruction sent by a user and determining interface information of a target interface to be monitored and at least one interface response configuration item based on the configuration instruction.
Based on this, the request receiving module of the interface simulation device is used for receiving a starting request of the application to be simulated, wherein the starting request carries a monitoring instruction; the request processing module is used for starting the application to be simulated based on the starting request and acquiring interface information of a target interface and at least one interface response configuration item based on the monitoring instruction; the interface calling monitoring module is used for judging whether a called target interface exists in the started application to be simulated or not based on the interface information; and the interface simulation module is used for responding to the existence of the called target interface in the started application to be simulated and simulating the called target interface based on the at least one interface response configuration item. The user can configure the interface information of the target interface and at least one interface response configuration item, namely, the monitoring and simulation of a plurality of target interfaces can be realized through configuration operation, and different simulations of the same target interface can also be realized by setting a plurality of interface response configuration items, so that the testing efficiency is improved.
The embodiment of the present disclosure further provides a computer-readable storage medium, in which instructions are stored, and when the computer executes the instructions, the computer executes each step in the method flow shown in the foregoing method embodiment.
Embodiments of the present disclosure provide a computer program product containing instructions which, when run on a computer, cause the computer to perform the interface simulation method in the above method embodiments.
Embodiments of the present disclosure provide a chip comprising a processor and a communication interface, the communication interface being coupled to the processor, the processor being configured to run a computer program or instructions to implement the interface simulation method as in the above method embodiments.
The computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, and a hard disk. Random Access Memory (RAM), read-Only Memory (ROM), erasable Programmable 5 Read Only Memory (EPROM), registers, a hard disk, an optical fiber, a portable Compact Disc Read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any other form of computer-readable storage medium, in any suitable combination, or values in the art. Showing device
An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium of 0. Of course, the storage medium may also be integral to the processor.
The processor and the storage medium may reside in an Application Specific Integrated Circuit (ASIC). In the embodiments of this disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
Since the apparatus, the device, the computer-readable storage medium, and the computer program product in the embodiments of the present disclosure may be applied to the method described above, for technical effects that can be obtained by the apparatus, the computer-readable storage medium, and the computer program product, reference may also be made to the embodiments of the method described above, which are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described device embodiment is merely illustrative, and for example, a module, a unit, and only one kind of logic function division may be implemented in other ways, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into 5 units.
The above description is only an embodiment of the present disclosure, but the scope of the present disclosure is not limited thereto, and any changes or substitutions within the technical scope of the present disclosure should be covered by the scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.

Claims (10)

1. A method for interface emulation, the method comprising:
receiving a starting request of an application to be simulated, wherein the starting request carries a monitoring instruction;
starting the application to be simulated based on the starting request, and acquiring interface information of a target interface and at least one interface response configuration item based on the monitoring instruction;
judging whether an invoked target interface exists in the started application to be simulated or not based on the interface information;
responding to the started application to be simulated to have the called target interface, and simulating the called target interface based on the at least one interface response configuration item.
2. The method according to claim 1, wherein the determining whether there is an invoked target interface in the started application to be simulated based on the interface information includes:
acquiring a called interface and interface information in the started application to be simulated;
and when the interface information of the target interface to be monitored has the same interface information as the called interface, judging that the called target interface exists in the application to be simulated.
3. The method of claim 1, wherein the interface response configuration item comprises: simulating an input parameter value, a simulated response value and the residual cycle number;
the simulating the called target interface based on the at least one interface response configuration item comprises:
acquiring an actual input parameter value corresponding to the called target interface, and judging whether each field in the simulated input parameter value is included in the actual input parameter value;
responding to each field in the actual input parameter value, wherein the field comprises the simulated input parameter value, and judging whether the residual cycle number is zero or not;
and if the residual cycle number is not zero, reducing the residual cycle number by one, and sending the simulation response value to a calling end for calling the called target interface.
4. The method of claim 3, wherein prior to obtaining interface information of a target interface and at least one interface response configuration item based on the monitoring instruction, the method further comprises:
the method comprises the steps of obtaining a configuration instruction sent by a user, and determining interface information of a target interface needing to be monitored and at least one interface response configuration item based on the configuration instruction.
5. An interface emulation device, comprising:
the device comprises a request receiving module, a monitoring module and a simulation module, wherein the request receiving module is used for receiving a starting request of an application to be simulated, and the starting request carries a monitoring instruction;
the request processing module is used for starting the application to be simulated based on the starting request and acquiring interface information of a target interface and at least one interface response configuration item based on the monitoring instruction;
the interface calling monitoring module is used for judging whether a called target interface exists in the started application to be simulated or not based on the interface information;
and the interface simulation module is used for responding to the existence of the called target interface in the started application to be simulated and simulating the called target interface based on the at least one interface response configuration item.
6. The apparatus of claim 5, wherein the interface call monitoring module comprises:
the interface information acquisition unit is used for acquiring the called interface and the interface information in the started application to be simulated;
and the target interface determining unit is used for judging that the called target interface exists in the application to be simulated when the interface information of the target interface to be monitored has the same interface information as the called interface.
7. The apparatus of claim 5, wherein the interface response configuration item comprises: simulating an input parameter value, a simulated response value and the residual cycle number;
the interface simulation module comprises:
the parameter input value judging unit is used for acquiring an actual parameter input value corresponding to the called target interface and judging whether each field in the simulated parameter input value is included in the actual parameter input value;
a residual cycle number judging unit, configured to respond to each field in the actual input parameter value that includes the simulated input parameter value, and judge whether the residual cycle number is zero;
and the simulation response unit is used for reducing the residual cycle number by one if the residual cycle number is not zero, and sending the simulation response value to a calling end for calling the called target interface.
8. The apparatus of claim 7, further comprising:
and the configuration instruction acquisition module is used for acquiring a configuration instruction sent by a user and determining interface information of a target interface to be monitored and at least one interface response configuration item based on the configuration instruction.
9. An interface emulation device, comprising: a processor and a memory; wherein the memory is configured to store computer-executable instructions that, when executed by the interface simulation apparatus, are executed by the processor to cause the interface simulation apparatus to perform the interface simulation method of any one of claims 1-4.
10. A computer-readable storage medium having instructions stored therein, which when executed by a processor of an interface simulation device, cause the interface simulation device to perform the interface simulation method of any one of claims 1-4.
CN202211379664.4A 2022-11-04 2022-11-04 Interface simulation method, device, equipment and storage medium Pending CN115904949A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211379664.4A CN115904949A (en) 2022-11-04 2022-11-04 Interface simulation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211379664.4A CN115904949A (en) 2022-11-04 2022-11-04 Interface simulation method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115904949A true CN115904949A (en) 2023-04-04

Family

ID=86485454

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211379664.4A Pending CN115904949A (en) 2022-11-04 2022-11-04 Interface simulation method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115904949A (en)

Similar Documents

Publication Publication Date Title
CN107766126B (en) Container mirror image construction method, system and device and storage medium
CN106649084B (en) The acquisition methods and device of function call information, test equipment
CN108345543B (en) Data processing method, device, equipment and storage medium
US7600220B2 (en) Extensible execution language
CN109302522A (en) Test method, device and computer system and medium
CN108459962A (en) Code specification detection method, device, terminal device and storage medium
CN111309620B (en) Game protocol testing method and device, electronic equipment and storage medium
WO2020211360A1 (en) Mock test method and system, electronic device, and computer non-volatile readable storage medium
CN113722020A (en) Interface calling method, device and computer readable storage medium
CN112328219A (en) Service access processing method, device and system and computer equipment
CN107977260B (en) Task submitting method and device
CN113868120A (en) Industrial software debugging method and device, computer equipment and storage medium
US8443292B2 (en) Scripting application with privacy mode coordination
US20230171179A1 (en) Method for testing pressure, electronic device and storage medium
CN115904949A (en) Interface simulation method, device, equipment and storage medium
KR20200048033A (en) Method and apparatus for testing javascript interpretation engine based on rewriting
CN114116509A (en) Program analysis method, program analysis device, electronic device, and storage medium
CN111240972B (en) Model verification device based on source code
CN113220586A (en) Automatic interface pressure test execution method, device and system
CN109492144B (en) Association relation analysis method, device and storage medium for software system
CN112685023A (en) Front-end development processing method, device, equipment and storage medium based on basic library
CN116028108B (en) Method, device, equipment and storage medium for analyzing dependent package installation time
CN116112377A (en) Interface simulation method, device, equipment and storage medium
CN115982035A (en) Interface data simulation method, device, equipment and storage medium
CN117931219A (en) Front-end project implementation method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination