Interface simulation test method, plug-in, terminal device and storage medium
By building a local simulated API object collection on the terminal device, the code pollution and docking problems caused by 'fake data' in front-end development are solved, and the front-end and back-end are completely separated and efficient development are achieved.
Patent Information
- Application Number
- CN202111596062.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-24
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2041-12-24
AI Technical Summary
In the development of web application separate from front and back ends, front-end developers need to define ‘fake data’ themselves for development, resulting in increased front-end code pollution and post-code cleaning work. At the same time, ‘fake data’ lacks some code for API calls, which adds post-domain docking work.
Provides an interface simulation test method and plug-in. By building a local simulation API object collection on the terminal device, matching and outputting simulation data, it realizes the complete separation of the front and back ends, reduces front-end code pollution, and simplifies the later docking work.
By imitating the collection of API objects locally, the front-end can independently complete development tasks, improve development efficiency, reduce code pollution and later code cleaning work, and simplify the API docking process.
Smart Images

Figure CN114265778B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of front-end development technology, and in particular to an interface simulation test method, a plug-in, a terminal device and a storage medium. Background Art
[0002] With the continuous development of Web (World Wide Web) front-end technology, the front-end and back-end separation development model has become the first choice for Web application development. In this model, API (Application Programming Interface) is the bridge for front-end and back-end interaction. Front-end developers only need to pay attention to the data returned by API and then render the data on the page without paying attention to the specific implementation logic of the back-end.
[0003] In today's Web application development process, the development progress of the front-end and back-end is often inconsistent. It takes a certain amount of time for the back-end to provide APIs, but the front-end needs data support during development. At this time, the front-end developers need to simulate data themselves, such as defining "fake data". However, defining "fake data" will cause front-end code pollution, increase the subsequent code cleaning work, and because "fake data" lacks some codes for API calls, it also increases the subsequent docking work. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide an interface simulation test method, plug-in, terminal device and storage medium to solve the problem that defining "fake data" will cause front-end code pollution, increase the subsequent code cleaning work, and because the "fake data" lacks some codes for API calls, it also increases the problem of subsequent docking work.
[0005] The present invention is achieved in that:
[0006] In the first aspect, an embodiment of the present application provides an interface simulation test method, which is applied to an interface simulation plug-in configured in a terminal device, and the method includes: receiving and parsing a request message sent by the terminal device; after determining that the simulation API function is turned on, matching the URL in the request message and the request method in the request message with a local simulation API object set; wherein the simulation API object set includes a request URL, a request method corresponding to the request URL, and simulation data corresponding to the request method; when the URL in the request message and the request method in the request message exist in the simulation API object set, outputting the simulation data corresponding to the request message in the simulation API object set.
[0007] In an embodiment of the present application, by constructing a local simulation API object set, the front-end and back-end (i.e., terminal device and server) can be completely separated, and the front-end can complete development tasks by itself, thereby improving development efficiency. At the same time, the local simulation API object set is different from the "fake data" constructed by code. In this way, front-end code pollution and subsequent code cleanup work can be reduced.
[0008] In combination with the technical solution provided in the first aspect above, in some possible implementation methods, the simulation API object set is generated through the following steps: obtaining the simulation API configured by the user; calling the simulation API, obtaining the data returned by the simulation API, and saving it to the simulation API configuration file; reading the simulation API configuration file, and creating the simulation API object set; wherein the simulation API object set adopts a Map data structure.
[0009] In an embodiment of the present application, a simple platform will be pre-built to provide a simulation API, so that the interface simulation plug-in can obtain the data returned by the simulation API and save it locally by calling the simulation API configured by the user. In the subsequent front-end development process, the call can be directly implemented through the interface simulation plug-in, thereby completely separating the front and back ends.
[0010] In combination with the technical solution provided in the first aspect above, in some possible implementations, the method further includes: detecting whether the simulation API configuration file is updated at preset intervals; if so, re-reading the simulation API configuration file to update the simulation API object set.
[0011] In the embodiment of the present application, the configuration file is checked by setting a preset time so as to update the simulation API object set in a timely manner.
[0012] In combination with the technical solution provided in the first aspect above, in some possible implementation methods, when the URL in the request message and the request method in the request message exist in the simulated API object set, and the request of the request message is a conditional query, the method also includes: determining the simulated data corresponding to the request message in the simulated API object set; filtering the simulated data based on the query condition corresponding to the request message; and outputting the filtered simulated data.
[0013] The interface simulation test provided in the embodiments of the present application can support a conditional query function.
[0014] In combination with the technical solution provided in the first aspect above, in some possible implementations, the method further includes: when the URL in the request message and the request method in the request message do not exist in the simulated API object set, or when it is determined that the simulated API function is not enabled, matching the host information in the request message and the port information in the request message with the local proxy object set; wherein the proxy object set includes local host information, local port information, and a real API server address corresponding to both the local host information and the local port information; when the host information in the request message and the port information in the request message exist in the proxy object set, the request message is directly sent to the real API server corresponding to both the host information in the request message and the port information in the request message.
[0015] In the embodiment of the present application, a proxy object set can also be constructed to realize real API forwarding. That is, the interface simulation test method provided in the embodiment of the present application can support the coexistence of real API and simulation API with the same URL, and the two do not affect each other.
[0016] In combination with the technical solution provided in the first aspect above, in some possible implementations, the proxy object set is generated through the following steps: obtaining a proxy configuration file configured by the user; wherein the proxy configuration file includes a proxy object; the proxy object includes the local host information, the local port information, and a real API server address corresponding to the local host information and the local port information; reading the proxy configuration file and creating the proxy object set; wherein the proxy object set is a list for storing proxy objects; each proxy object includes the local host information, the local port information, and the real API server address corresponding to the two.
[0017] In the embodiment of the present application, the creation of the proxy object set is achieved by reading the proxy configuration file configured by the user.
[0018] In the second aspect, an embodiment of the present application provides an interface simulation plug-in, which is configured on a terminal device, and includes: a receiving module, which is used to receive and parse the request message sent by the terminal device; a simulation API object matching module, which, after determining that the simulation API function is turned on, matches the URL in the request message and the request method in the request message with a local simulation API object set; wherein the simulation API object set includes a request URL, a request method corresponding to the request URL, and simulation data corresponding to the request method; a simulation API output module, which, when the URL in the request message and the request method in the request message exist in the simulation API object set, outputs the simulation data in the simulation API object set corresponding to the request message.
[0019] In combination with the technical solution provided in the second aspect above, in some possible implementation methods, the interface simulation plug-in also includes: a configuration module; the configuration module is used to obtain the simulation API configured by the user; call the simulation API, obtain the data returned by the simulation API, and save it to the simulation API configuration file; read the simulation API configuration file, and create the simulation API object set; wherein the simulation API object set adopts a Map data structure.
[0020] In a third aspect, an embodiment of the present application provides a terminal device, comprising: a processor and a memory, wherein the processor and the memory are connected; the memory is used to store programs; the processor is used to call the programs stored in the memory to execute the method provided in the above-mentioned first aspect embodiment and / or in combination with some possible implementation methods of the above-mentioned first aspect embodiment.
[0021] In a fourth 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, executes a method provided in the embodiment of the first aspect above and / or in combination with some possible implementations of the embodiment of the first aspect above. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0023] Figure 1 A module block diagram of a terminal device provided in an embodiment of the present application.
[0024] Figure 2A flowchart of an interface simulation test method provided in an embodiment of the present application.
[0025] Figure 3 A schematic diagram of a Map data structure provided in an embodiment of the present application.
[0026] Figure 4 A module block diagram of an interface simulation plug-in provided in an embodiment of the present application.
[0027] Icon: 100 - terminal device; 110 - processor; 120 - memory; 200 - interface simulation plug-in; 210 - receiving module; 220 - simulation API object matching module; 230 - simulation API output module. DETAILED DESCRIPTION
[0028] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0029] See also Figure 1 , a schematic structural block diagram of a terminal device 100 of an application interface simulation test method and apparatus provided in an embodiment of the present application. In the embodiment of the present application, the terminal device 100 may be, but is not limited to, a personal computer (PC), a notebook computer, and the like.
[0030] It should be noted that the terminal device 100 is the front end in the subsequent embodiments, and the back end refers to the server.
[0031] Structurally, the terminal device 100 may include a processor 110 and a memory 120 .
[0032] The processor 110 is electrically connected to the memory 120 directly or indirectly to realize data transmission or interaction. For example, these elements can be electrically connected to each other through one or more communication buses or signal lines. The interface simulation plug-in includes at least one software module that can be stored in the memory 120 in the form of software or firmware or solidified in the operating system (OS) of the terminal device 100. The processor 110 is used to execute the executable modules stored in the memory 120, for example, the software function modules and computer programs included in the interface simulation plug-in, to implement the interface simulation test method. The processor 110 can execute the computer program after receiving the execution instruction.
[0033] The processor 110 may be an integrated circuit chip with signal processing capability. The processor 110 may also be a general-purpose processor, for example, a central processing unit (CPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. In addition, the general-purpose processor may be a microprocessor or any conventional processor.
[0034] The memory 120 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), and an electric erasable programmable read-only memory (EEPROM). The memory 120 is used to store a program, and the processor 110 executes the program after receiving an execution instruction.
[0035] It should be noted that Figure 1 The structure shown is for illustration only. The terminal device 100 provided in the embodiment of the present application may also have Figure 1 Fewer or more components, or with Figure 1 In addition, Figure 1 The components shown may be implemented by software, hardware or a combination thereof.
[0036] See also Figure 2 , Figure 2 A flowchart of the interface simulation test method provided in the embodiment of the present application, which is applied to Figure 1 It should be noted that the interface simulation test method provided in the embodiment of the present application is not based on Figure 2 The order shown below is limited, and the method includes: step S101-step S104.
[0037] Step S101: Receive and parse a request message sent by a terminal device.
[0038] The interface simulation test method provided in the embodiment of the present application can be implemented through an interface simulation plug-in.
[0039] The interface simulation plug-in can be a vscode plug-in, which can realize API simulation and forwarding functions through vscode plug-in API and nodeJs (a JavaScript runtime environment based on Chrome V8 engine). The size of the plug-in is only 1M (unit: megabyte), which is lightweight and easy to use.
[0040] After the interface simulation plug-in is started, it is initialized and first checks whether the configuration folder exists. If it does not exist, it creates a .vscode / good-tool / folder in the project directory. It should be noted that the .vscode / good-tool / folder is a folder for storing configurations uniformly. File updates in this folder can automatically trigger the reading of configuration files.
[0041] Then, the interface simulation plug-in is configured. In the embodiment of the present application, the configured files include: a simulation API configuration file and a proxy configuration file.
[0042] The interface simulation plug-in is specifically used to obtain the simulation API configured by the user; then call the simulation API, obtain the data returned by the simulation API, and save it to the simulation API configuration file. That is, if the user builds a simple backend by himself, and the backend provides an API for querying the API definition list, then the interface simulation plug-in calls the API, obtains the data returned by the API, and saves it to the simulation API configuration file.
[0043] The proxy configuration file is directly configured by the user. The proxy configuration file includes the local host information, the local port information, and the real API server address corresponding to the local host information and the local port information.
[0044] After obtaining the simulation API configuration file, the interface simulation plug-in creates a simulation API object set based on the simulation API configuration file, wherein the simulation API object set includes a request URL, a request method corresponding to the request URL, and simulation data corresponding to the request method.
[0045] That is, the simulation API object set includes multiple simulation API objects, each simulation API object includes a request URL, a request method corresponding to the request URL, and simulation data corresponding to the request method.
[0046] In the embodiments of the present application, the simulated API object collection can use a Map data structure. Map is a key-value collection. The Map type can usually be understood as an associative array: a key can be used as a subscript to obtain a value, just like a built-in array type. The essence of association is that the value of an element is associated with a specific key, rather than being obtained by the position of the element in the array. Please refer to Figure 3 , the simulated API object set includes the keys: GET, POST, PUT, DELETE. The value corresponding to GET is the simulated API object array with the request method GET (i.e. the corresponding simulated data), the value corresponding to POST is the simulated API object array with the request method POST (i.e. the corresponding simulated data), the value corresponding to PUT is the simulated API object array with the request method PUT (i.e. the corresponding simulated data), and the value corresponding to DELETE is the simulated API object array with the request method DELETE (i.e. the corresponding simulated data).
[0047] The above method is used to realize asynchronous modification of configuration and query of configuration progress. For some APIs with time-consuming configuration operations, there are many background steps, and asynchronous background tasks often need to be issued. At the same time, the front end needs to display the current execution steps and execution progress in real time. In the process of executing background tasks, there may be multiple states, such as: exception, success, failure, etc., and different states need to display different UIs (User Interfaces). It is difficult to simulate various states and real-time progress without providing an API in the background, which hinders the development of the front-end page. When the above solution is adopted, after configuring the simulation API, you only need to modify the value corresponding to the field in the configuration to update the status and progress instantly, so that the front end can easily write logic code and adjust the page UI.
[0048] Correspondingly, after obtaining the proxy configuration file configured by the user, the interface simulation plug-in reads the proxy configuration file and creates a proxy object set; wherein the proxy object set is a list for storing proxy objects; each proxy object includes local host information, local port information and the real API server address corresponding to the two.
[0049] After the interface simulation plug-in creates the simulation API object set and the proxy object set, they are stored in the configuration folder, and a HTTP (Hyper Text Transfer Protocol) service is opened locally to receive all requests. That is, the interface simulation plug-in executes step S101: receiving and parsing the request message sent by the terminal device.
[0050] It can be seen that in the embodiment of the present application, a simple platform will be pre-built to provide a simulation API, so that the interface simulation plug-in can obtain the data returned by the simulation API and save it locally by calling the simulation API configured by the user. In the subsequent front-end development process, the call can be directly implemented through the interface simulation plug-in, thereby completely separating the front and back ends. At the same time, by reading the proxy configuration file configured by the user to create a proxy object collection, it is also convenient to realize the subsequent real API forwarding.
[0051] In other embodiments, the interface simulation plug-in may also only create a set of simulated API objects, which is not limited in this application.
[0052] Step S102: After determining that the simulation API function is turned on, the URL (Uniform Resource Locator) in the request message and the request method in the request message are matched with the local simulation API object set; wherein the simulation API object set includes the request URL, the request method corresponding to the request URL, and the simulation data corresponding to the request method.
[0053] After receiving the request message, the interface simulation plug-in will first determine whether to enable the simulation API function (which can be set in the interface simulation plug-in configuration, and is enabled by default). After determining that the simulation API function is enabled, the interface simulation plug-in matches the URL and the request method in the request message with the local simulation API object set. If the same URL and request method are matched, step S103 is executed.
[0054] Step S103: when the URL in the request message and the request method in the request message exist in the simulated API object set, output the simulated data corresponding to the request message in the simulated API object set.
[0055] When the simulated API object set contains the URL in the request message and the request method in the request message, the simulated data corresponding to the request message in the simulated API object set is directly output. It should be noted that the simulated data is output from the configuration folder stored locally, rather than being retrieved from the background or generated by simulating fake data through code.
[0056] In addition, in actual development, the URL written in the code is often different from the URL of the actual request. The method of requesting the API is often encapsulated and has a fixed prefix, so fuzzy matching can be used by default when matching. As long as the requested URL contains the configured URL, the match can be successful. You can also enable exact matching in the plug-in configuration. This application does not limit this.
[0057] It can be seen that in the embodiments of the present application, by constructing a local simulation API object set, the front-end and back-end (i.e., the terminal device and the server) can be completely separated, and the front-end can complete the development tasks by itself, thereby improving development efficiency. At the same time, the local simulation API object set is different from the "fake data" constructed by the code. This method can reduce front-end code pollution and subsequent code cleanup work.
[0058] In one embodiment, when the URL in the request message and the request method in the request message exist in the simulated API object set, and the request of the request message is a conditional query, the above method also includes: determining the simulated data corresponding to the request message in the simulated API object set; filtering the simulated data based on the query conditions corresponding to the request message; and outputting the filtered simulated data.
[0059] For the conditional query function in the GET request, you can select the parameter module in the plug-in configuration. By default, the request parameters of the filter query of the Table component in antd are used.
[0060] When doing comprehensive conditional queries, the objects in the data list returned by the backend API may be different. The front end needs to process different objects differently and display different UIs. If the data is defined in the code, a lot of junk code will be created, which is troublesome to modify and it is impossible to write API call code. When using the above solution, all possible data can be added to the configuration file at one time. When developing or testing, the conditional query parameters can be passed in to get the data that the developer wants, so as to perform rendering and debugging.
[0061] In one embodiment, the method further includes: detecting whether the simulation API configuration file is updated at preset intervals; if so, re-reading the simulation API configuration file to update the simulation API object set.
[0062] Of course, it is also possible to detect whether the proxy configuration file is updated at each preset time; if so, re-read the proxy configuration file to update the proxy object set.
[0063] The preset time may be, but is not limited to, 3 seconds, 5 seconds, or 10 seconds. The configuration file is checked by setting the preset time so as to update the simulation API object set in a timely manner.
[0064] Specifically, the above configuration files can all use the .json format files familiar to the front end, and specify the proxy configuration file as proxy.json, while the name of the simulation API configuration file can have no other restrictions, and multiple can be created. For the simulation API configuration file, when reading the configuration file, all files in the configuration folder will be obtained, and files that are not in .json format will be filtered out. Then, all objects in the configuration file will be placed in an array, and then traversed. Different simulation API objects are distinguished according to the request method, and finally they will be placed in a Map with the key as the request method and the value as the simulation API object array (classification by request method is to facilitate different operations for different types of requests and facilitate later functional expansion). When the plug-in is initialized, a timer will be set to check whether there are any file updates in the configuration folder every 3 seconds (preset time). If so, the configuration file reading operation will be re-executed. The interval for checking configuration file updates can be modified in the plug-in configuration.
[0065] After determining that the simulation API function is not enabled, or when the URL in the request message and the request method in the request message do not exist in the simulation API object set, the method further includes: matching the host information in the request message and the port information in the request message with the local proxy object set; wherein the proxy object set includes local host information, local port information, and a real API server address corresponding to both the local host information and the local port information; when the host information in the request message and the port information in the request message exist in the proxy object set, the request message is directly sent to the real API server corresponding to both the host information in the request message and the port information in the request message.
[0066] That is, the interface simulation plug-in supports real API forwarding, so that the interface simulation test method provided in the embodiment of the present application can support the coexistence of real API and simulation API with the same URL without affecting each other.
[0067] At the same time, the API forwarding function supports two configuration modes. One is unified configuration, which is to directly configure the destination API server (real API server address) in the plug-in configuration. The other is batch configuration, which is configured in proxy.json. You can configure multiple different source addresses (host information + local port used for project startup) and destination addresses (host information + port of the real API server). If there are multiple identical source addresses corresponding to different destination addresses, the matching result will be the last one in the configuration file.
[0068] In large projects, the front end may need to connect to more than one backend, and they all have their own development environments. Sometimes a bug is found in the test environment, but it is difficult to reproduce in the development environment for some reason, so the front end needs to switch the backend environment. Usually, you need to modify the project proxy configuration and restart the project, or modify the Nginx configuration and restart it through Nginx (a high-performance HTTP and reverse proxy web server), which is cumbersome and wastes a lot of time. When using the above solution, you only need to modify the configuration in the proxy.json file to take effect immediately.
[0069] See also Figure 4 Based on the same inventive concept, the embodiment of the present application further provides an interface simulation plug-in 200, the device comprising:
[0070] The receiving module 210 is used to receive and parse the request message sent by the terminal device.
[0071] The simulation API object matching module 220, after determining that the simulation API function is turned on, matches the URL in the request message and the request method in the request message with the local simulation API object set; wherein the simulation API object set includes the request URL, the request method corresponding to the request URL, and the simulation data corresponding to the request method.
[0072] The simulation API output module 230 outputs simulation data corresponding to the request message in the simulation API object set when the URL in the request message and the request method in the request message exist in the simulation API object set.
[0073] Optionally, the interface simulation plug-in further includes: a configuration module.
[0074] The configuration module is used to obtain the simulation API configured by the user; call the simulation API, obtain the data returned by the simulation API, and save it to the simulation API configuration file; read the simulation API configuration file and create the simulation API object set; wherein the simulation API object set adopts a Map data structure.
[0075] Optionally, the configuration module is further configured to detect whether the simulation API configuration file is updated at preset intervals; if so, re-read the simulation API configuration file to update the simulation API object set.
[0076] Optionally, the simulation API output module is also used to determine the simulation data corresponding to the request message in the simulation API object set when the URL in the request message and the request method in the request message exist in the simulation API object set and the request of the request message is a conditional query; filter the simulation data based on the query condition corresponding to the request message; and output the filtered simulation data.
[0077] Optionally, the device further includes a real API object matching module. The real API object matching module is used to match the host information in the request message and the port information in the request message with the local proxy object set when the URL in the request message and the request method in the request message do not exist in the simulated API object set, or when it is determined that the simulated API function is not enabled; wherein the proxy object set includes local host information, local port information, and a real API server address corresponding to both the local host information and the local port information; when the host information in the request message and the port information in the request message exist in the proxy object set, the request message is directly sent to the real API server corresponding to both the host information in the request message and the port information in the request message.
[0078] Correspondingly, the configuration module is also used to obtain a proxy configuration file configured by the user; wherein the proxy configuration file includes a proxy object; the proxy object includes the local host information, the local port information and the real API server address corresponding to the local host information and the local port information; read the proxy configuration file and create the proxy object set; wherein the proxy object set is a list for storing proxy objects; each proxy object includes the local host information, the local port information and the real API server address corresponding to the two.
[0079] It should be noted that, since technicians in the relevant field can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0080] Based on the same inventive concept, an embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed, the method provided in the above embodiment is executed.
[0081] The storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more available media. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, a tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)).
[0082] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0083] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0084] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0085] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0086] The above description is only an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the scope of protection of the present application.
Claims
1. An interface simulation test method, characterized in that: Applied to an interface simulation plug-in configured in a terminal device, the method comprises: Receiving and parsing the request message sent by the terminal device; After determining that the simulation API function is enabled, matching the URL in the request message and the request method in the request message with a local simulation API object set; wherein the simulation API object set includes a plurality of simulation API objects, each of which includes a request URL, a request method corresponding to the request URL, and simulation data corresponding to the request method; When the URL in the request message and the request method in the request message exist in the simulated API object set, output the simulated data corresponding to the request message in the simulated API object set; The method further comprises: When the URL in the request message and the request method in the request message do not exist in the simulated API object set, or when it is determined that the simulated API function is not enabled, the host information in the request message and the port information in the request message are matched with the local proxy object set; wherein the proxy object set includes the local host information, the local port information and the real API server address corresponding to the local host information and the local port information; When the host information in the request message and the port information in the request message exist in the proxy object set, the request message is directly sent to the real API server corresponding to the host information in the request message and the port information in the request message; wherein, at preset time intervals, it is detected whether the proxy configuration file is updated; if so, the proxy configuration file is re-read to update the proxy object set; the proxy configuration file includes proxy objects.
2. The method according to claim 1, characterized in that The simulation API object set is generated by the following steps: Get the simulated API configured by the user; Call the simulation API, obtain the data returned by the simulation API, and save it to the simulation API configuration file; The simulation API configuration file is read to create the simulation API object set; wherein the simulation API object set adopts a Map data structure.
3. The method according to claim 2, characterized in that The method further comprises: At preset intervals, detecting whether the simulated API configuration file is updated; If so, the simulation API configuration file is re-read to update the simulation API object set.
4. The method according to claim 1, characterized in that: When the URL in the request message and the request method in the request message exist in the simulated API object set, and the request in the request message is a conditional query, the method further includes: Determining simulation data corresponding to the request message in the simulation API object set; Filtering the simulation data based on the query condition corresponding to the request message; Output the filtered simulation data.
5. The method according to claim 1, characterized in that The proxy object set is generated by the following steps: Obtaining a proxy configuration file configured by a user; the proxy object includes the local host information, the local port information, and a real API server address corresponding to both the local host information and the local port information; The proxy configuration file is read to create the proxy object set; wherein the proxy object set is a list storing proxy objects; each proxy object includes the local host information, the local port information and the real API server address corresponding to the two.
6. An interface simulation plug-in, characterized in that: Configured on terminal equipment, including: A receiving module, used for receiving and parsing the request message sent by the terminal device; A simulation API object matching module, after determining that the simulation API function is turned on, matches the URL in the request message and the request method in the request message with a local simulation API object set; wherein the simulation API object set includes a plurality of simulation API objects, each of which includes a request URL, a request method corresponding to the request URL, and simulation data corresponding to the request method; A simulation API output module, when the URL in the request message and the request method in the request message exist in the simulation API object set, outputs simulation data corresponding to the request message in the simulation API object set; The interface simulation plug-in further includes: when the URL in the request message and the request method in the request message do not exist in the simulation API object set, or when it is determined that the simulation API function is not enabled, matching the host information in the request message and the port information in the request message with a local proxy object set; wherein the proxy object set includes local host information, local port information, and a real API server address corresponding to both the local host information and the local port information; When the host information in the request message and the port information in the request message exist in the proxy object set, the request message is directly sent to the real API server corresponding to the host information in the request message and the port information in the request message; wherein, at preset time intervals, it is detected whether the proxy configuration file is updated; if so, the proxy configuration file is re-read to update the proxy object set; the proxy configuration file includes proxy objects.
7. The interface simulation plug-in according to claim 6, characterized in that: The interface simulation plug-in also includes: a configuration module; The configuration module is used to obtain the simulation API configured by the user; call the simulation API, obtain the data returned by the simulation API, and save it to the simulation API configuration file; read the simulation API configuration file and create the simulation API object set; wherein the simulation API object set adopts a Map data structure.
8. A terminal device, characterized in that: include: A processor and a memory, the processor and the memory being connected; The memory is used to store programs; The processor is used to run the program stored in the memory to execute the method according to any one of claims 1 to 5.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a computer, the method according to any one of claims 1 to 5 is executed.
Citation Information
Patent Citations
Remote data simulation method and a remote virtual server
CN109768951A
Interface call test method and device and computer readable storage medium
CN110990205A
Mock test method and device, electronic equipment and medium
CN113190464A