A method and system for running an application program interface, a computer device and a medium
By selecting a data simulation strategy to obtain simulated data based on the runtime environment when a request is received from an application interface to be run, the problem of difficulty in obtaining data under different environments is solved, and the running efficiency of the application interface is improved.
Patent Information
- Application Number
- CN202210987985.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-17
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2042-08-17
AI Technical Summary
Existing technologies cannot quickly acquire data for application interfaces to run in different operating environments, resulting in low operating efficiency.
When a request is received from an application interface to be run, multiple target application interfaces associated with it are identified, and different data simulation strategies are selected according to the running environment to obtain simulation data. Finally, the running results are generated based on the simulation data.
It enables rapid data acquisition under different operating environments, improving the operating efficiency of the application programming interface.
Smart Images

Figure CN115202907B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a running method and system of application program interface, computer device and medium. BACKGROUND
[0002] With the vigorous development of software system, when the application program interface in the system is running, other application program interfaces need to be debugged. Only when the application program interface debugging is performed, the development demand will continue. If the application program interface debugging cannot be performed, the data should be obtained, and the program cannot be executed. Therefore, how to quickly obtain data during the application program interface debugging is a problem that the research and development personnel hope to solve.
[0003] In the prior art, in order to obtain the response data, the following two methods are usually used: first, in the development environment, a complete third-party service is built, and the data returned by the real call interface in the development environment is obtained. Second, the third-party application program interface is directly annotated in the code, a preset string is used to simulate the data returned by the interface, and then the preset string is mapped to the interface return object. In this way, the data returned by the third-party application program interface is simulated. Since the two existing methods consume a lot of resources when building the third-party service, and changing the code will cause inconvenience to system development, it is impossible to quickly obtain data for application program interface running in different running environments, thereby reducing the running efficiency of the application program interface. SUMMARY
[0004] Therefore, it is necessary to provide a running method and system of application program interface, computer device and medium for solving the problem that data cannot be quickly obtained for application program interface running in different running environments.
[0005] A running method of application program interface, the method comprising: determining a plurality of target application program interfaces associated with a to-be-run application program interface when a running request of the to-be-run application program interface is received; determining a data simulation strategy of the plurality of target application program interfaces according to a running environment in which the to-be-run application program interface is located; obtaining simulation data of the plurality of target application program interfaces according to the determined data simulation strategy; running the to-be-tested application program interface based on the simulation data, and generating a running result.
[0006] In one of the embodiments, the running environment of the application interface to be run includes a local development environment, a test environment and a production line environment; the data simulation strategy of the plurality of target application interfaces is determined according to the current running environment, including: when the running environment of the application interface to be run is the local development environment, a local data processing strategy is acquired; the local data processing strategy is determined as the data simulation strategy of the plurality of target application interfaces; or, when the running environment of the application interface to be run is the test environment, a database data processing strategy is acquired; the database data processing strategy is determined as the data simulation strategy of the plurality of target application interfaces; or, when the running environment of the application interface to be run is the production line environment, a cache data processing strategy is acquired; the cache data processing strategy is determined as the data simulation strategy of the plurality of target application interfaces.
[0007] In one of the embodiments, the simulation data of the plurality of target application interfaces is acquired according to the determined data simulation strategy, including: if the data simulation strategy is the local data processing strategy, a local data storage path is acquired; a local storage file is connected according to the local data storage path; the simulation data of the plurality of target application interfaces is acquired in the local storage file.
[0008] In one of the embodiments, the simulation data of the plurality of target application interfaces is acquired according to the determined data simulation strategy, including: if the data simulation strategy is the database data processing strategy, a target database is connected; the simulation data of the plurality of target application interfaces is acquired in the target database; or, if the data simulation strategy is the cache data processing strategy, a cache server is connected; the simulation data of the plurality of target application interfaces is acquired in the cache server.
[0009] In one of the embodiments, when the running request of the application interface to be run is received, before the plurality of target application interfaces associated with the application interface to be run is determined, it further includes: when the data simulation strategy configuration instruction for the application interface is received, the data simulation strategy is configured according to the data simulation strategy configuration instruction; the data simulation switch is started for the configured data simulation strategy, so as to receive the running request of the application interface to be run.
[0010] In one of the embodiments, the plurality of target application interfaces associated with the application interface to be run is determined, including: a plurality of interface keywords in the code segment corresponding to the application interface to be run are acquired; the application interface identifier indicated by each interface keyword is collected to obtain a plurality of application interface identifiers; the application interface corresponding to each application interface identifier in the system code is acquired to obtain the plurality of target application interfaces.
[0011] In one of the embodiments, the application interface to be tested is run based on the simulation data, the running result is generated, including: obtaining data type identifiers and function scripts existing in the code segment corresponding to the application interface to be tested; associating the simulation data with the obtained data type identifiers one by one to obtain variable data; inputting the variable data into the function script for data processing, and outputting the running result.
[0012] A running system of an application interface, the system comprising: a target application interface determination module, configured to determine a plurality of target application interfaces associated with an application interface to be run when receiving a running request of the application interface to be run; a data simulation strategy determination module, configured to determine data simulation strategies of the plurality of target application interfaces according to a running environment in which the application interface to be run is located; a simulation data acquisition module, configured to acquire simulation data of the plurality of target application interfaces according to the determined data simulation strategies; and a running result generation module, configured to run the application interface to be tested based on the simulation data, and generate a running result.
[0013] A computer device comprising a memory and a processor, the memory storing computer readable instructions, the computer readable instructions being executed by the processor to cause the processor to perform the steps of the running method of the application interface.
[0014] A medium storing computer readable instructions, the computer readable instructions being executed by one or more processors to cause the one or more processors to perform the steps of the running method of the application interface.
[0015] The running method, system, device and medium of the application interface, the running system of the application interface first determines a plurality of target application interfaces associated with an application interface to be run when receiving a running request of the application interface to be run, then determines data simulation strategies of the plurality of target application interfaces according to a running environment in which the application interface to be run is located, then acquires simulation data of the plurality of target application interfaces according to the determined data simulation strategies, and finally runs the application interface to be tested based on the simulation data, and generates a running result. Since different data simulation strategies are adopted according to different running environments of the application interface to acquire data, the data can be quickly obtained for running the application interface under different running environments, and the running efficiency of the application interface is improved. BRIEF DESCRIPTION OF DRAWINGS
[0016] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the application.
[0017] Figure 1This is a diagram illustrating the implementation environment of the running method of the application programming interface provided in one embodiment of this application.
[0018] Figure 2 This is a schematic diagram of the internal structure of a computer device in one embodiment of this application;
[0019] Figure 3 This is a schematic diagram illustrating the operation method of the application programming interface provided in one embodiment of this application;
[0020] Figure 4 This is a schematic diagram of the method for running the application interface provided in another embodiment of this application;
[0021] Figure 5 This is a schematic diagram of the system architecture of an application programming interface (API) running system provided in an embodiment of this application. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0023] It is understood that the terms “first,” “second,” etc., used in this application may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another.
[0024] Figure 1 This is a diagram illustrating the implementation environment of the application programming interface (API) running method provided in one embodiment, such as... Figure 1 As shown, this implementation environment includes a server 110 and a client 120.
[0025] Server 110 can be a server, specifically a standalone server or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. For example, it could be a server device storing simulated data. When client 120 receives a run request for an application interface to be run, it identifies multiple target application interfaces associated with that interface. Client 120 determines a data simulation strategy for these target application interfaces based on their runtime environment. Client 120 connects to server 110 and retrieves simulated data for the target application interfaces from server 110 according to the determined data simulation strategy. Client 120 then runs the application interface to be tested based on the simulated data and generates the running results.
[0026] It should be noted that the client 120 can be a smartphone, tablet, laptop, desktop computer, etc., but is not limited to these. The server 110 and the client 120 can connect via Bluetooth, USB (Universal Serial Bus), or other communication connection methods, which are not limited in this invention.
[0027] Figure 2 This is a schematic diagram of the internal structure of a computer device in one embodiment. For example... Figure 2 As shown, the computer device includes a processor, media, memory, and network interface connected via a system bus. The media of the computer device stores an operating system, a database, and computer-readable instructions. The database may store a sequence of control information. When the computer-readable instructions are executed by the processor, they enable the processor to implement an application programming interface (API) execution method. The processor of the computer device provides computing and control capabilities to support the operation of the entire device. The memory of the computer device may store computer-readable instructions, which, when executed by the processor, enable the processor to execute an API execution method. The network interface of the computer device is used for communication with a terminal. Those skilled in the art will understand that... Figure 2 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. A specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements. The medium is a readable storage medium.
[0028] The following will be combined with the appendix Figures 3-4This application provides a detailed description of the method for running the application programming interface (API) provided in its embodiments. This method can be implemented using a computer program and can run on an application programming interface based on the von Neumann architecture. The computer program can be integrated into an application or run as a standalone utility application.
[0029] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0030] Foundational technologies in artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, large application programming interface (API) operation technologies, operating / interaction systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.
[0031] Please see Figure 3 This is a flowchart illustrating a method for running an application programming interface (API) according to an embodiment of this application. Figure 3 As shown, the method in this application embodiment may include the following steps:
[0032] S101, upon receiving a run request for an application interface to be run, determine multiple target application interfaces associated with the application interface to be run;
[0033] The application programming interface (API) can be a Dubbo interface. Dubbo is an open-source distributed service framework, and more and more software systems are based on it. When system engineers develop systems using Dubbo as their underlying technology, they inevitably need to interact with third-party Dubbo interfaces. Dubbo (an open-source distributed service framework) is a high-performance service framework open-sourced by Alibaba, enabling applications to achieve service input and output functions through high-performance RPC. An API is an interface that uses Dubbo to implement a data interaction protocol and uses this protocol to transmit data. An interface is the concrete implementation of functional methods, such as the interface for login or registration.
[0034] Typically, in real-world business scenarios, a software system contains application programming interfaces (APIs) to be run, as well as multiple target APIs from third parties that interact with the APIs to be run. The APIs to be run and the multiple target APIs from third parties can work together to achieve a specific function.
[0035] In this embodiment of the application, before the application interface runs, the configuration file of the software system also needs to be configured. First, when a data simulation strategy configuration instruction for the application interface is received, the data simulation strategy is configured according to the data simulation strategy configuration instruction. Then, the data simulation switch is activated for the configured data simulation strategy to receive the running request of the application interface to be run.
[0036] For example, you can introduce Dubbo-related preset function packages into the microservice application system of the software system, and then enable the switch to simulate application interface data in the system configuration. Y means enabled, and N means disabled. For example, you can configure it as dubbo_mock_enable_switch=Y. You can also enable the simulation method of simulated application interface data in the configuration, for example, you can configure it as Dubbo_mock_way=local,mysql,redis, where local means to obtain simulated data locally, mysql means to obtain simulated data through MySQL, and redis means to obtain simulated data through Redis.
[0037] In one possible implementation, upon receiving a request to run an application interface to be run, firstly, multiple interface keywords are obtained from the code snippet corresponding to the application interface to be run; then, the application interface identifiers indicated by each interface keyword are collected to obtain multiple application interface identifiers; finally, the application interface corresponding to each application interface identifier is obtained from the system code to obtain multiple target application interfaces.
[0038] For example, a user generates an instruction by triggering a specific function in the software system, and this instruction, together with the interface of the application to be run, constructs a run request.
[0039] S102, determine the data simulation strategy for multiple target application interfaces based on the runtime environment of the application interface to be run;
[0040] The runtime environment of the application interface to be run includes the local development environment, the testing environment, and the production environment.
[0041] In one possible implementation, when the runtime environment of the application interface to be run is the local development environment, the local data processing strategy is obtained, and then the local data processing strategy is determined as the data simulation strategy for multiple target application interfaces.
[0042] For example, when a user triggers a specific function in a software system within their local development environment, the local data processing strategy can be defined as a data simulation strategy for multiple target application interfaces. This local data processing strategy is suitable for self-testing and integration in a local development environment; local files can be modified instantly to change interface data without requiring a project restart, making it convenient and practical.
[0043] In another possible implementation, when the runtime environment of the application interface to be run is a test environment, the database data processing strategy is first obtained, and then the database data processing strategy is used as the data simulation strategy for multiple target application interfaces.
[0044] For example, when a user triggers a specific function in the software system during a test environment, the database data processing strategy can be defined as a data simulation strategy for multiple target application interfaces. In the test environment, test engineers do not have permission to modify local file data on the test machine; they can only simulate interface data by modifying the test database. This strategy can address the data needs of test engineers in the test environment.
[0045] In another possible implementation, when the runtime environment of the application interface to be run is a production line environment, the cache data processing strategy is first obtained, and then the cache data processing strategy is used as the data simulation strategy for multiple target application interfaces.
[0046] For example, when a user triggers a specific function in a software system within a production environment, the cached data processing strategy can be defined as a data simulation strategy for multiple target application interfaces. This approach is suitable for environments where local files cannot be modified and the `dubbo_mock_data` table cannot be created in the database. It is commonly used in production environments, where simulated data can be configured in the cache to simulate the production environment, and once the cache is cleared, the method immediately resumes normal invocation.
[0047] S103, Obtain simulation data for multiple target application interfaces according to the determined data simulation strategy;
[0048] In one possible implementation, if the data simulation strategy is a local data processing strategy, the local data storage path is first obtained, then the local storage file is connected according to the local data storage path, and finally the simulation data of multiple target application interfaces is obtained from the local storage file.
[0049] Specifically, during the generation of local storage files, mock data can be stored in a local path, such as D:\dubbo\mock\, with the filename prefixed with the interface path name_method name.json. For example, the file com.pinganfu.***.facade.***Facade_send***.json (with key data and masking) stores the mock data for this third-party application interface.
[0050] "respCode":"000000",
[0051] "respMsg":"Success"
[0052] }
[0053] In another possible implementation, if the data simulation strategy is a database data processing strategy, then the target database is connected, and then simulation data of multiple target application interfaces is obtained from the target database.
[0054] Specifically, when generating the target database, the application interface simulation data is configured in the MySQL persistent database. Database connection information is added to the system configuration, and then a new table, `dubbo_mock_data`, is created in the database, containing two fields: `method` and `mock_data`. The `method` field stores the interface path and method name, for example, `com.pinganfu.***.facade.***Facade_send***`. The `mock_data` field stores the specific JSON data simulated under this application interface, for example, `{"respCode":"000000","respMsg":"Success"}`.
[0055] In another possible implementation, if the data simulation strategy is a cached data processing strategy, then a connection is made to a cache server, and simulated data for multiple target application interfaces is retrieved from the cache server. The cache server is preferably a Redis cache.
[0056] Specifically, the application interface is configured to simulate data in the cache, service connection information is added in the system configuration, and the specified key-value pairs are created in the server.
[0057] The key is the interface path and method name.
[0058] For example, com.pinganfu.***.facade.***Facade_send***
[0059] Value is the simulated JSON data for this interface.
[0060] {"respCode":"000000","respMsg":"Success"}.
[0061] S104 runs the application interface under test based on simulated data and generates the running results.
[0062] In one possible implementation, when running the application interface to be tested based on simulated data and generating the running results, the data type identifiers and function scripts existing in the code snippet corresponding to the application interface to be tested are first obtained. Then, the simulated data is associated with the obtained data type identifiers one by one to obtain variable data. Finally, the variable data is input into the function script for data processing and the running results are output.
[0063] In this embodiment, the application programming interface (API) runtime system first identifies multiple target APIs associated with the API upon receiving a runtime request. Then, it determines a data simulation strategy for each target API based on its runtime environment. Next, it acquires simulated data for the target APIs according to the determined data simulation strategy. Finally, it runs the API under test based on the simulated data, generating runtime results. Because this application employs different data simulation strategies to acquire data based on different runtime environments of the API, it can quickly obtain data for the API to run in different environments, thereby improving the runtime efficiency of the API.
[0064] Please see Figure 4 This is a flowchart illustrating a method for running an application programming interface (API) according to an embodiment of this application. Figure 4 As shown, the method in this application embodiment may include the following steps:
[0065] 1. Upon receiving a request to run an application interface, retrieve multiple interface keywords from the code snippet corresponding to the application interface to be run;
[0066] 2. Collect the application interface identifiers indicated by each interface keyword to obtain multiple application interface identifiers;
[0067] 3. Obtain the application interface corresponding to each application interface identifier in the system code to obtain multiple target application interfaces;
[0068] 4. Determine the runtime environment of the application interface to be run;
[0069] 4.1 When the application interface to be run is in a local development environment, obtain the local data processing strategy;
[0070] 4.2. Define the local data processing strategy as a data simulation strategy for multiple target application programming interfaces;
[0071] 4.3 If the data simulation strategy is a local data processing strategy, then obtain the local data storage path, connect to the local storage file according to the local data storage path, and obtain the simulation data of multiple target application interfaces from the local storage file;
[0072] 4.5 When the application interface to be run is in a test environment, obtain the database data processing strategy;
[0073] 4.6. Use the database data processing strategy as a data simulation strategy for multiple target application interfaces;
[0074] 4.7 If the data simulation strategy is a database data processing strategy, then connect to the target database and obtain simulation data of multiple target application interfaces from the target database;
[0075] 4.8 When the application interface to be run is in a production line environment, obtain the cache data processing strategy;
[0076] 4.9. Use the cached data processing strategy as a data simulation strategy for multiple target application interfaces;
[0077] 4.10 If the data simulation strategy is a cached data processing strategy, then connect to the cache server and obtain the simulation data of multiple target application interfaces from the cache server;
[0078] 5. Run the application interface to be tested based on the simulated data and generate the running results.
[0079] In this embodiment, the application programming interface (API) runtime system first identifies multiple target APIs associated with the API upon receiving a runtime request. Then, it determines a data simulation strategy for each target API based on its runtime environment. Next, it acquires simulated data for the target APIs according to the determined data simulation strategy. Finally, it runs the API under test based on the simulated data, generating runtime results. Because this application employs different data simulation strategies to acquire data based on different runtime environments of the API, it can quickly obtain data for the API to run in different environments, thereby improving the runtime efficiency of the API.
[0080] The following are system embodiments of the present invention, which can be used to execute the method embodiments of the present invention. For details not disclosed in the system embodiments of the present invention, please refer to the method embodiments of the present invention.
[0081] Please seeFigure 5 This illustration shows a schematic diagram of the operating system of an application programming interface (API) provided in an exemplary embodiment of the present invention. The operating system of this API can be implemented as all or part of a device through software, hardware, or a combination of both. System 1 includes a target application programming interface (API) determination module 10, a data simulation strategy determination module 20, a simulation data acquisition module 30, and an operation result generation module 40.
[0082] The target application interface determination module 10 is used to determine multiple target application interfaces associated with the application interface to be run when a run request is received from the application interface to be run.
[0083] The data simulation strategy determination module 20 is used to determine the data simulation strategy of multiple target application interfaces based on the running environment of the application interface to be run.
[0084] The simulation data acquisition module 30 is used to acquire simulation data of multiple target application interfaces according to a determined data simulation strategy;
[0085] The result generation module 40 is used to run the application interface under test based on the simulated data and generate the results.
[0086] It should be noted that the application programming interface (API) runtime system provided in the above embodiments is only illustrated by the division of the above functional modules when executing the API runtime method. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the API runtime system and the API runtime method embodiments provided in the above embodiments belong to the same concept, and the implementation process is detailed in the method embodiments, which will not be repeated here.
[0087] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0088] In this embodiment, the application programming interface (API) runtime system first identifies multiple target APIs associated with the API upon receiving a runtime request. Then, it determines a data simulation strategy for each target API based on its runtime environment. Next, it acquires simulated data for the target APIs according to the determined data simulation strategy. Finally, it runs the API under test based on the simulated data, generating runtime results. Because this application employs different data simulation strategies to acquire data based on different runtime environments of the API, it can quickly obtain data for the API to run in different environments, thereby improving the runtime efficiency of the API.
[0089] In one embodiment, a computer device is provided, the device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to perform the following steps:
[0090] Upon receiving a run request for an application interface to be run, identify multiple target application interfaces associated with the application interface to be run;
[0091] Determine the data simulation strategy for multiple target application interfaces based on the runtime environment of the application interfaces to be run;
[0092] Based on the determined data simulation strategy, obtain simulation data for multiple target application interfaces;
[0093] Run the application interface under test based on simulated data and generate the results.
[0094] In one embodiment, when the processor executes a data simulation strategy to determine multiple target application interfaces based on the current operating environment, it specifically performs the following operations:
[0095] When the application interface to be run is in a local development environment, obtain the local data processing strategy;
[0096] The local data processing strategy is defined as a data simulation strategy for multiple target application interfaces;
[0097] or,
[0098] When the application interface to be run is in a test environment, obtain the database data processing strategy;
[0099] The database data processing strategy is used as a data simulation strategy for multiple target application interfaces;
[0100] or,
[0101] When the application interface to be run is in a production line environment, obtain the cached data processing strategy;
[0102] The cached data processing strategy is used as a data simulation strategy for multiple target application interfaces.
[0103] In one embodiment, when the processor executes the operation of acquiring simulated data for multiple target application interfaces according to a determined data simulation strategy, it specifically performs the following operations:
[0104] If the data simulation strategy is a local data processing strategy, then obtain the local data storage path;
[0105] Connect to local storage files based on the local data storage path;
[0106] Retrieve simulated data from multiple target application interfaces from local storage files.
[0107] In one embodiment, when the processor executes the operation of acquiring simulated data for multiple target application interfaces according to a determined data simulation strategy, it specifically performs the following operations:
[0108] If the data simulation strategy is a database data processing strategy, then connect to the target database;
[0109] Retrieve simulated data for multiple target application interfaces from the target database;
[0110] or,
[0111] If the data simulation strategy is a cached data processing strategy, then connect to the cache server;
[0112] Retrieve simulated data from multiple target application interfaces in the cache server.
[0113] In one embodiment, before the processor determines the multiple target application interfaces associated with the application interface to be run upon receiving a run request for the application interface to be run, it also performs the following operations:
[0114] Upon receiving a data simulation strategy configuration instruction for the application interface, configure the data simulation strategy according to the data simulation strategy configuration instruction;
[0115] Enable the data simulation switch for the configured data simulation policy to receive run requests from application interfaces to be run.
[0116] In one embodiment, when the processor executes the operation to determine multiple target application interfaces associated with the application interface to be run, it performs the following operations:
[0117] Retrieve multiple interface keywords from the code snippet corresponding to the interface of the application to be run;
[0118] Collect the application interface identifiers indicated by each interface keyword to obtain multiple application interface identifiers;
[0119] The system code retrieves the application interface corresponding to each application interface identifier, resulting in multiple target application interfaces.
[0120] In one embodiment, when the processor executes the test application interface based on simulated data and generates the results, it specifically performs the following operations:
[0121] Obtain the data type identifiers and function scripts present in the code snippets corresponding to the interfaces of the application under test;
[0122] By associating the simulated data with the acquired data type identifiers one by one, the variable data is obtained;
[0123] Input variable data into a function script for data processing and output the results.
[0124] In this embodiment, the application programming interface (API) runtime system first identifies multiple target APIs associated with the API upon receiving a runtime request. Then, it determines a data simulation strategy for each target API based on its runtime environment. Next, it acquires simulated data for the target APIs according to the determined data simulation strategy. Finally, it runs the API under test based on the simulated data, generating runtime results. Because this application employs different data simulation strategies to acquire data based on different runtime environments of the API, it can quickly obtain data for the API to run in different environments, thereby improving the runtime efficiency of the API.
[0125] In one embodiment, a medium storing computer-readable instructions is provided, which, when executed by one or more processors, cause the one or more processors to perform the following steps:
[0126] Upon receiving a run request for an application interface to be run, identify multiple target application interfaces associated with the application interface to be run;
[0127] Determine the data simulation strategy for multiple target application interfaces based on the runtime environment of the application interfaces to be run;
[0128] Based on the determined data simulation strategy, obtain simulation data for multiple target application interfaces;
[0129] Run the application interface under test based on simulated data and generate the results.
[0130] In one embodiment, when the processor executes a data simulation strategy to determine multiple target application interfaces based on the current operating environment, it specifically performs the following operations:
[0131] When the application interface to be run is in a local development environment, obtain the local data processing strategy;
[0132] The local data processing strategy is defined as a data simulation strategy for multiple target application interfaces;
[0133] or,
[0134] When the application interface to be run is in a test environment, obtain the database data processing strategy;
[0135] The database data processing strategy is used as a data simulation strategy for multiple target application interfaces;
[0136] or,
[0137] When the application interface to be run is in a production line environment, obtain the cached data processing strategy;
[0138] The cached data processing strategy is used as a data simulation strategy for multiple target application interfaces.
[0139] In one embodiment, when the processor executes the operation of acquiring simulated data for multiple target application interfaces according to a determined data simulation strategy, it specifically performs the following operations:
[0140] If the data simulation strategy is a local data processing strategy, then obtain the local data storage path;
[0141] Connect to local storage files based on the local data storage path;
[0142] Retrieve simulated data from multiple target application interfaces from local storage files.
[0143] In one embodiment, when the processor executes the operation of acquiring simulated data for multiple target application interfaces according to a determined data simulation strategy, it specifically performs the following operations:
[0144] If the data simulation strategy is a database data processing strategy, then connect to the target database;
[0145] Retrieve simulated data for multiple target application interfaces from the target database;
[0146] or,
[0147] If the data simulation strategy is a cached data processing strategy, then connect to the cache server;
[0148] Retrieve simulated data from multiple target application interfaces in the cache server.
[0149] In one embodiment, before the processor determines the multiple target application interfaces associated with the application interface to be run upon receiving a run request for the application interface to be run, it also performs the following operations:
[0150] Upon receiving a data simulation strategy configuration instruction for the application interface, configure the data simulation strategy according to the data simulation strategy configuration instruction;
[0151] Enable the data simulation switch for the configured data simulation policy to receive run requests from application interfaces to be run.
[0152] In one embodiment, when the processor executes the operation to determine multiple target application interfaces associated with the application interface to be run, it performs the following operations:
[0153] Retrieve multiple interface keywords from the code snippet corresponding to the interface of the application to be run;
[0154] Collect the application interface identifiers indicated by each interface keyword to obtain multiple application interface identifiers;
[0155] The system code retrieves the application interface corresponding to each application interface identifier, resulting in multiple target application interfaces.
[0156] In one embodiment, when the processor executes the test application interface based on simulated data and generates the results, it specifically performs the following operations:
[0157] Obtain the data type identifiers and function scripts present in the code snippets corresponding to the interfaces of the application under test;
[0158] By associating the simulated data with the acquired data type identifiers one by one, the variable data is obtained;
[0159] Input variable data into a function script for data processing and output the results.
[0160] In this embodiment, the application programming interface (API) runtime system first identifies multiple target APIs associated with the API upon receiving a runtime request. Then, it determines a data simulation strategy for each target API based on its runtime environment. Next, it acquires simulated data for the target APIs according to the determined data simulation strategy. Finally, it runs the API under test based on the simulated data, generating runtime results. Because this application employs different data simulation strategies to acquire data based on different runtime environments of the API, it can quickly obtain data for the API to run in different environments, thereby improving the runtime efficiency of the API.
[0161] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This computer program can be stored in a computer-readable medium, and when executed, it can include the processes of the embodiments of the methods described above. The aforementioned medium can be a non-volatile medium such as a magnetic disk, optical disk, or read-only memory (ROM), or random access memory (RAM).
[0162] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0163] The above embodiments merely illustrate several implementation methods of the present invention, and their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this patent should be determined by the appended claims.
Claims
1. A method for running an application programming interface (API), characterized in that, The method includes: Upon receiving a request to run an application interface to be run, identify multiple target application interfaces associated with the application interface to be run; The data simulation strategy for the multiple target application interfaces is determined based on the operating environment of the application interface to be run; wherein... The runtime environment of the application interface to be run includes the local development environment, the testing environment, and the production line environment; Determining the data simulation strategy for the plurality of target application interfaces includes: When the runtime environment of the application interface to be run is a local development environment, obtain the local data processing strategy; determine the local data processing strategy as the data simulation strategy for the multiple target application interfaces; or... When the runtime environment of the application interface to be run is a test environment, obtain the database data processing strategy; use the database data processing strategy as the data simulation strategy for the multiple target application interfaces; or... When the running environment of the application interface to be run is a production line environment, obtain the cache data processing strategy; use the cache data processing strategy as the data simulation strategy of the multiple target application interfaces; Simulation data for the multiple target application interfaces is obtained according to the determined data simulation strategy; Run the application interface to be tested based on the simulated data and generate the results.
2. The method according to claim 1, characterized in that, The step of obtaining simulation data for the multiple target application interfaces according to the determined data simulation strategy includes: If the data simulation strategy is a local data processing strategy, then obtain the local data storage path; Connect to local storage files based on the local data storage path; The simulated data of the multiple target application interfaces are obtained from the local storage file.
3. The method according to claim 1, characterized in that, The step of obtaining simulation data for the multiple target application interfaces according to the determined data simulation strategy includes: If the data simulation strategy is a database data processing strategy, then connect to the target database; Retrieve simulated data of the multiple target application interfaces from the target database; or, If the data simulation strategy is a cached data processing strategy, then connect to the cache server; The simulated data of the multiple target application interfaces are obtained from the cache server.
4. The method according to claim 1, characterized in that, Before determining the multiple target application interfaces associated with the application interface to be run upon receiving a run request from the application interface to be run, the method further includes: Upon receiving a data simulation strategy configuration instruction for the application interface, configure the data simulation strategy according to the data simulation strategy configuration instruction; Enable the data simulation switch for the configured data simulation policy to receive run requests from application interfaces to be run.
5. The method according to claim 1, characterized in that, The determination of multiple target application interfaces associated with the application interface to be run includes: Retrieve multiple interface keywords from the code snippet corresponding to the interface of the application to be run; Collect the application interface identifiers indicated by each interface keyword to obtain multiple application interface identifiers; The system code retrieves the application interface corresponding to each application interface identifier, resulting in multiple target application interfaces.
6. The method according to claim 1, characterized in that, The process of running the application interface under test based on the simulated data and generating the running results includes: Obtain the data type identifiers and function scripts present in the code snippet corresponding to the interface of the application to be tested; The simulated data is associated with the acquired data type identifiers one by one to obtain variable data; The variable data is input into the function script for data processing, and the running result is output.
7. A runtime system using an application programming interface implemented according to any one of claims 1-6, characterized in that, The system includes: The target application interface determination module is used to determine multiple target application interfaces associated with the application interface to be run when a run request is received from the application interface to be run. A data simulation strategy determination module is used to determine the data simulation strategy of the multiple target application interfaces based on the operating environment of the application interface to be run. The simulation data acquisition module is used to acquire simulation data of the multiple target application interfaces according to a determined data simulation strategy; The result generation module is used to run the application interface under test based on the simulated data and generate the results.
8. A computer device, characterized in that, It includes a memory and a processor, wherein the memory stores computer-readable instructions that, when executed by the processor, cause the processor to perform the steps of the method for operating the application interface as claimed in any one of claims 1 to 6.
9. A medium storing computer-readable instructions, characterized in that, When the computer-readable instructions are executed by one or more processors, they cause the one or more processors to perform the steps of the method of operating the application interface as claimed in any one of claims 1 to 6.
Citation Information
Patent Citations
Front-end code testing method, device and system based on analog data and medium
CN109726108A
Interface test method and device, computer equipment and storage medium
CN112363941A