Dynamic interface simulation method and device, electronic equipment and storage medium

By injecting the target interface of the server through probes, intercepting and generating dynamic simulation responses, the problem of the inability to update the simulated interface in real time in the prior art is solved, improving the stability and security of the application, and improving the efficiency of interface testing.

CN120216350APending Publication Date: 2025-06-27BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202311799089.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-25
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

In the prior art, it is impossible to dynamically update the configuration of the simulated interface and modify the behavior of the simulated interface in real time, resulting in low stability and security of the application.

Method used

Through the target interface of the probe injection server, target requests sent by the client are intercepted based on the surface-oriented programming technology and interceptor technology, and dynamic simulation responses are generated based on dynamic configuration data, and sent to the server to generate target responses.

Benefits of technology

It realizes dynamic updates of the configuration and behavior of simulated interfaces in real time without modifying the source code of the host application, improving the stability and security of the application, and improving the efficiency and flexibility of interface testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120216350A_ABST
    Figure CN120216350A_ABST
Patent Text Reader

Abstract

The invention provides an interface dynamic simulation method and device, electronic equipment and a computer readable storage medium, and relates to the technical field of interface testing. The method comprises the following steps: in response to a target interface of a probe injection server, the probe intercepts a target request sent by a client to the server based on at least one of a section-oriented programming technology and an interceptor technology, generates a dynamic simulation response according to dynamic configuration data through the probe, and sends the dynamic simulation response to the server, the server generates a target response according to the dynamic simulation response, and the target response is used for responding to a target request of the client; according to the embodiment of the invention, the source code of the host application program does not need to be modified, the configuration of the simulation interface and the behavior of modifying the simulation interface can be dynamically updated in real time, and the stability and safety of the application program can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] Mock testing means that during the testing process, for some complex objects that are not easy to construct or obtain, a virtual mock object can be created for testing; in the related art, HTTP (Hypertext Transfer Protocol) interface mock can be achieved through open-source mock servers, API (Application Programming Interface) test automation tools, etc., but it is necessary to modify the source code of the host application, and the stability and security of the application are relatively low, and the configuration of the mock interface cannot be updated in real time dynamically and the behavior of the mock interface cannot be modified.

[0003] It should be noted that the information disclosed in the above background art section is only used to enhance the understanding of the background of the present disclosure, and thus may include information that does not constitute the prior art known to those of ordinary skill in the art. Summary of the Invention

[0004] The present disclosure provides an interface dynamic simulation method, apparatus, electronic device and computer-readable storage medium, which at least overcome to a certain extent the problem in the related art that the mock interface cannot be modified in real time dynamically.

[0005] Other features and advantages of the present disclosure will become apparent through the following detailed description, or will be learned in part through the practice of the present disclosure.

[0006] According to one aspect of the present disclosure, there is provided an interface dynamic simulation method, including: in response to a probe injecting into a target interface of a server, intercepting a target request sent by a client to the server based on the probe; generating a dynamic simulation response by the probe according to dynamic configuration data; wherein the dynamic configuration data is data for dynamically configuring a mock interface; and sending the dynamic simulation response to the server so that the server generates a target response according to the dynamic simulation response for responding to the target request of the client.

[0007] In an embodiment of the present disclosure, the dynamic configuration method of the dynamic configuration data includes at least one of the following: dynamically configuring the dynamic configuration data through a configuration file;

[0008] dynamically configuring the dynamic configuration data by adding a custom annotation to the target interface;

[0009] dynamically configuring the dynamic configuration data by interacting with a dynamic data source.

[0010] In one embodiment of the present disclosure, the dynamic configuration data includes at least one of: interface path, request method, request header, request body, and simulated response.

[0011] In one embodiment of the present disclosure, it further includes: generating the dynamic simulated response according to at least one of the dynamic configuration data and preset static data.

[0012] In one embodiment of the present disclosure, the responding to the probe injecting into the target interface of the server, and intercepting the target request sent by the client to the server based on the probe includes: in response to the probe injecting into the target interface of the server, the probe intercepts the target request sent by the client to the server based on at least one of aspect-oriented programming technology and interceptor technology.

[0013] In one embodiment of the present disclosure, the injection method of the probe injecting into the target interface of the server includes at least one of the following:

[0014] Modifying the bytecode of the server based on a bytecode manipulation library, and inserting the probe code into the method of the target interface;

[0015] Applying a newly created proxy class to add probe code in the method of the target interface.

[0016] In one embodiment of the present disclosure, it further includes: expanding the function of the probe by adding at least one of a custom plugin and a defined extension point to the target interface through the probe, where the functions of the probe include at least one of request logging, assertion verification, and performance analysis.

[0017] According to another aspect of the present disclosure, there is also provided an interface dynamic simulation device, including:

[0018] A request interception module that, in response to a probe injecting into a target interface of a server, intercepts a target request sent by a client to the server based on the probe;

[0019] A response generation module that generates a dynamic simulated response through the probe according to dynamic configuration data; where the dynamic configuration data is data for dynamically configuring a simulated interface;

[0020] A request response module that sends the dynamic simulated response to the server so that the server generates a target response according to the dynamic simulated response for responding to the target request of the client.

[0021] According to another aspect of the present disclosure, there is also provided an electronic device, including: a processor; and a memory for storing executable instructions of the processor; wherein, the processor is configured to execute the interface dynamic simulation method described in any one of the above via executing the executable instructions.

[0022] According to another aspect of the present disclosure, there is also provided a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the interface dynamic simulation method described in any one of the above is implemented.

[0023] For the interface dynamic simulation method, device, electronic device and computer-readable storage medium provided by the embodiments of the present disclosure, in response to a target interface of the probe injection server, the probe intercepts a target request sent by the client to the server based on at least one of aspect-oriented programming technology and interceptor technology, generates a dynamic simulation response according to dynamic configuration data through the probe, and sends the dynamic simulation response to the server, so that the server generates a target response according to the dynamic simulation response for responding to the target request of the client; without modifying the source code of the host application, it can dynamically update the configuration of the simulation interface and modify the behavior of the simulation interface in real time, improving the stability and security of the application.

[0024] It should be understood that the above general description and subsequent detailed description are only exemplary and explanatory, and cannot limit the present disclosure. Description of the Drawings

[0025] The drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present disclosure, and are used together with the specification to explain the principles of the present disclosure. Obviously, the drawings in the following description are only some embodiments of the present disclosure, and those of ordinary skill in the art can obtain other drawings based on these drawings without creative efforts.

[0026] Figure 1 Showing a flowchart of an interface dynamic simulation method in an embodiment of the present disclosure;

[0027] Figure 2 Showing a flowchart of a target request interception method in an embodiment of the present disclosure;

[0028] Figure 3 Showing a flowchart of a dynamic simulation response generation method in an embodiment of the present disclosure;

[0029] Figure 4 Showing a schematic diagram of an interface dynamic simulation device in an embodiment of the present disclosure;

[0030] Figure 5 Showing a flowchart of another interface dynamic simulation method in an embodiment of the present disclosure;

[0031] Figure 6 Shows a schematic diagram of an interface dynamic simulation system in an embodiment of the present disclosure;

[0032] Figure 7 Shows a structural block diagram of an electronic device in an embodiment of the present disclosure. Detailed implementation manners

[0033] Now, example embodiments will be described more fully with reference to the accompanying drawings. However, the example embodiments can be implemented in various forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be more thorough and complete, and will fully convey the concept of the example embodiments to those skilled in the art. The described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments.

[0034] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus repeated descriptions thereof will be omitted. Some of the block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0035] The following will describe the example embodiments in detail with reference to the accompanying drawings and embodiments.

[0036] First, an interface dynamic simulation method is provided in an embodiment of the present disclosure, and this method can be executed by any electronic device with computing and processing capabilities.

[0037] Figure 1 Shows a flowchart of an interface dynamic simulation method in an embodiment of the present disclosure. As Figure 1 shown, the interface dynamic simulation method provided in the embodiment of the present disclosure includes the following steps:

[0038] S102, in response to the target interface of the probe injection server, intercept the target request sent by the client to the server based on the probe.

[0039] The probe in the embodiments of this application may adopt the JDK (Java Development Kit, the version of Java development tools). For example, versions such as JDK5 and JDK6. In JDK5, the Java probe parameters can only be set by command-line parameters when starting the JVM (Java Virtual Machine) to set the proxy class. However, in JDK6, it is not limited to setting the proxy class through configuration parameters when starting the JVM. In JDK6, through the attach method in the Java Tool API, the proxy class can be dynamically set and loaded during the running process to achieve the purpose of Instrumentation. Instrumentation is a probe class provided by the JDK. The biggest function of Instrumentation is the dynamic change and operation of class definition.

[0040] Java probe (Java Agent). A Java probe is a piece of code injected into a Java application for monitoring, modifying, or enhancing the behavior of the application; it can achieve the interception and control of the application through bytecode injection or proxy mode.

[0041] The target interface is an HTTP interface (HTTP API). The HTTP interface is a communication interface based on the HTTP protocol, used for data exchange and communication between different systems; by sending HTTP requests and receiving HTTP responses, the application can perform data interaction and service calls with other systems.

[0042] In one embodiment, the injection method of the probe into the target interface of the server includes but is not limited to at least one of the following: modifying the bytecode of the server based on a bytecode operation library and inserting the probe code into the method of the target interface; applying a newly created proxy class of the application to add the probe code to the method of the target interface.

[0043] In one embodiment, in response to the probe being injected into the target interface of the server, the probe intercepts the target request sent by the client to the server through at least one interception method among technologies such as aspect-oriented programming technology and interceptor technology.

[0044] AOP (Aspect-Oriented Programming): AOP is a programming paradigm used to separate cross-cutting concerns (such as logging, performance monitoring, etc.) from the main business logic; it decouples the cross-cutting concerns from the core business logic by defining aspects in the code.

[0045] An interceptor is a component that intercepts and processes requests in an application. It can perform specific operations such as logging, permission verification, performance monitoring, etc. before or after the request reaches the target.

[0046] S104, generate a dynamic simulation response according to the dynamic configuration data through a probe; wherein, the dynamic configuration data is data for dynamically configuring a simulation interface.

[0047] In one embodiment, the dynamic configuration data includes, but is not limited to, at least one of: interface path, request method, request header, request body, and simulation response.

[0048] Mock Response: A mock response is a virtual response used to replace the real interface return during the testing or development phase. The mock response can be predefined static data or dynamically generated data, that is, the mock response can be a dynamically simulated response corresponding to the target request set in advance or in real time, that is, status code, response header, and response body, etc.

[0049] In one embodiment, the dynamic configuration method of the dynamic configuration data includes, but is not limited to, at least one of the following: dynamically configure the dynamic configuration data through a configuration file; dynamically configure the dynamic configuration data by adding custom annotations to the target interface; dynamically configure the dynamic configuration data by interacting with a dynamic data source, etc.

[0050] Configuration File: A configuration file is a file used to store and manage application configuration information. Developers can define the behavior, parameters, and other related settings of the application through the configuration file.

[0051] The dynamic data source is a database, file system, network service, distributed configuration center, etc. that stores the dynamic configuration data of the simulation interface; it supports driving the behavior of the simulation interface through the dynamic data source; data-driven is a testing and development method in which the input and expected output of the test scenario are provided by an external data source; Data-Driven can help test cover more scenarios and improve the accuracy and reliability of the test.

[0052] In one implementation, generating a dynamic simulation response according to at least one data such as dynamic configuration data and preset static data can flexibly define the rules and responses of the simulation interface, improving the efficiency and flexibility of interface testing.

[0053] The preset static data is the mock response data hard-coded and predefined in the probe code. For example, a mock response object can be created through configuration methods such as a configuration file or adding custom annotations to the target interface, and the corresponding status code, response header, and response body, etc. can be set. The status code, response header, response body, mock response data, etc. can also be hard-coded and predefined in the probe code.

[0054] S106, send the dynamic simulation response to the server so that the server generates a target response according to the dynamic simulation response for responding to the target request of the client.

[0055] In one embodiment, at least one of a custom plug-in and an extension point is added to the target interface through a probe to extend the functions of the probe. The functions of the probe include, but are not limited to, at least one of request logging, assertion verification, performance analysis, etc.; that is, by reserving some empty implementations, users can complete the registration of extension points and the customization of plug-ins by inheriting the empty implementations; for example, mainly the mock methods and data customized by users.

[0056] In one embodiment, a custom plug-in interface is defined and implemented in the target interface, and developers can add custom plug-ins according to needs to extend the functions of the probe, such as request logging, assertion verification, performance analysis, etc.; for example, a custom plug-in can be implemented through MyBatis.

[0057] In one embodiment, an extension point interface and corresponding implementation classes are defined in the target interface through an Eclipse plug-in, and developers can register and call these extension points in the probe to implement additional functions, such as request logging, assertion verification, performance analysis, etc.

[0058] In one embodiment, at least one of a target response and a dynamic mock response includes, but is not limited to, a status line, a response header, a response body, etc.

[0059] In one embodiment, the dynamic mock response is sent to the server, and the server can directly send the dynamic mock response to the client to respond to the target request of the client, or the server can also encapsulate the dynamic mock response and other processes to generate a target response for responding to the target request of the client. For example, the size, type, etc. of the response body in the dynamic mock response are changed.

[0060] In the above embodiments, a Java probe is used to inject into the application server and intercept HTTP requests, realizing the ability of dynamic HTTP interface simulation. The behavior and response of the simulation interface are flexibly defined through configuration, that is, the path, request method, request header, request body, etc. of the simulation interface, and the corresponding simulation response is specified; and through dynamic data driving, the simulation response can be generated according to real-time data, so as to simulate different test scenarios; there is no need to restart the application, and there is no need to modify the source code of the host application, protecting the stability and security of the application, and improving the efficiency and flexibility of interface testing, providing fast and reliable integration testing.

[0061] Figure 2 The flowchart of a target request interception method in an embodiment of the present disclosure is shown, as Figure 2 As shown, the target request interception method provided in the embodiment of the present disclosure includes the following steps:

[0062] S202. Based on at least one method among modifying the bytecode of the server and the newly created proxy class using a bytecode manipulation library, inject a probe into the target interface of the server. By using the probe, the behavior of the mock interface can be modified in real time to meet the requirements of different test scenarios.

[0063] In one embodiment, bytecode manipulation libraries such as ASM, Javassist, JDK, CGLIB, etc. can be used to modify the bytecode of the server and insert the probe code into the methods of the target interface. It should be noted that for the methods that need to be mocked based on bytecode modification, encapsulate the mocked data and return it to the client. The mocked data can be dynamically modified through configuration to achieve the purpose of dynamic mocking. For example, when the user requests " / user / a", the information "ok" needs to be returned.

[0064] In one embodiment, create a new proxy class to add probe code in the methods of the target interface and use this new proxy class in the application to replace the original interface implementation to achieve the purpose of dynamic mocking.

[0065] S204. The probe intercepts the target request sent by the client to the server based on at least one interception method such as aspect-oriented programming technology and interceptor technology, reducing the invasiveness to the host application and protecting the stability and security of the application.

[0066] In one embodiment, intercept the target request sent by the client to the server based on aspect-oriented programming technology. Among them, aspect-oriented programming technology includes but is not limited to: AspectJ, Spring AOP, etc.

[0067] In one embodiment, the interceptor intercepts the target request sent by the client to the server. Among them, the interceptor includes but is not limited to: Java Servlet filters or Spring interceptors, etc.

[0068] S206. Generate a dynamic mock response through the probe according to the dynamic configuration data.

[0069] Through a configuration file or other means, the dynamic configuration data of the mock interface can be updated in real time without restarting the application.

[0070] In one embodiment, after the probe intercepts the target request, encapsulate the dynamic mock response and then return it to the server.

[0071] In the above embodiments, by using a Java probe, the behavior of the simulated interface can be modified in real time to meet the requirements of different test scenarios. The rules and responses of the simulated interface can be defined flexibly. Through a configuration file or other means, the configuration of the simulated interface can be updated in real time without restarting the application. By using aspects or other bytecode technologies, the interception and processing of HTTP requests can be achieved without modifying the source code of the host application, reducing the invasiveness to the host application and protecting the stability and security of the application.

[0072] Figure 3 The flowchart of a dynamic simulation response generation method in an embodiment of the present disclosure is shown, as Figure 3 shown, the dynamic simulation response generation method provided in the embodiment of the present disclosure includes the following steps:

[0073] S302, Configure dynamic configuration data through dynamic configuration methods such as configuration files, adding custom annotations to the target interface, and interacting with dynamic data sources. The rules and responses of the simulated interface can be defined flexibly. The behavior of the simulated interface can be modified in real time without restarting the application, and the requirements of different test scenarios can be met.

[0074] In one embodiment, dynamic configuration data can be configured based on a proxy server, a Mock server, a simulation framework, etc., that is, the behavior and response of the simulated interface are defined.

[0075] Proxy server: Use a proxy server to intercept and forward HTTP requests of the application, thereby achieving dynamic simulation. The proxy server can define the behavior and response of the simulated interface according to a configuration file or other means.

[0076] Mock server: Set up a dedicated Mock server for simulating the behavior and response of HTTP interfaces. Developers can use this server to configure and define the behavior of the simulated interface in real time.

[0077] Simulation framework: Use existing simulation frameworks such as WireMock, MockServer, Mountebank, Karate, REST Assured, etc. These frameworks provide the ability to dynamically simulate interfaces; developers can use these frameworks to configure and define the behavior and response of the simulated interface.

[0078] WireMock: WireMock is a powerful HTTP interface simulation and testing library. It provides a Java API and an independent simulation server, which can be used to create and configure simulated interfaces, define responses, and perform assertion verification.

[0079] MockServer: MockServer is an open-source mock server that can be used to simulate and test interfaces of HTTP, HTTPS, and other protocols. It provides client libraries in Java and other languages, which can be used to create and configure mock interfaces, define responses, and perform assertion validations.

[0080] Mountebank: Mountebank is an open-source mock server that can be used to simulate and test interfaces of protocols such as HTTP, TCP, and SMTP. It provides a flexible configuration and plugin mechanism to meet various interface simulation and validation requirements.

[0081] Karate: Karate is an open-source API test automation tool that combines an HTTP client and an assertion library and can be used to simulate and test HTTP interfaces. Karate uses a concise syntax to write test scripts and supports functions such as simulating interfaces, assertion validations, and data-driven testing.

[0082] REST Assured: REST Assured is a popular Java library for writing interface tests and integration tests. It provides a concise API that can be used to simulate HTTP requests and responses, perform assertion validations, and extract data, etc.

[0083] In one embodiment, developers can implement dynamic mocks by writing custom code. This may involve using techniques such as reflection and dynamic bytecode generation to intercept and modify the HTTP requests of the application, and implementing the replacement of the dynamically configurable functional parts through custom code.

[0084] In one embodiment, the formats of configuration files include but are not limited to: ini, conf, xml, json, yaml, properties, etc. The behavior of the mock interface is defined through the configuration file to implement dynamic configuration data, and the dynamic configuration data is obtained by reading the configuration file.

[0085] In one embodiment, a custom annotation is added to the method of the target interface, and the dynamic configuration information of the mock interface is obtained and applied by parsing this custom annotation.

[0086] In one embodiment, the dynamic data source is a database, file system, network service, distributed configuration center, etc. that stores the dynamic configuration data of the mock interface. The distributed configuration center includes but is not limited to: Zookeeper, Eureka, Nacos, Consul, Etcd, etc.; the probe code interacts with the dynamic data source to dynamically obtain the dynamic configuration information and perform corresponding processing according to the dynamic configuration information.

[0087] S304, Obtain data such as dynamic configuration data and preset static data.

[0088] The preset static data is predefined simulated response data hard-coded in the probe code. For example, a simulated response object can be created through configuration methods such as configuration files or adding custom annotations to the target interface, and the corresponding status code, response headers, and response body can be set. It is also possible to hard-code predefined status codes, response headers, response bodies, simulated response data, etc. in the probe code.

[0089] Obtain real-time dynamic configuration information from external dynamic data sources such as databases, file systems, and network services, and use it for the generation of dynamic simulated responses to achieve a dynamic data-driven simulation effect.

[0090] In one embodiment, based on relevant Java libraries and APIs, interact with the dynamic data source to obtain real-time dynamic configuration information; the APIs include but are not limited to: JDBC, file I / O, network request libraries, etc.

[0091] S306, Generate a dynamic simulated response based on at least one of the data such as dynamic configuration data and preset static data.

[0092] In the above embodiment, the behavior of the simulated interface can be modified in real time using the probe. Through the configuration file or other means, the configuration of the simulated interface can be updated in real time without restarting the application, meeting the requirements of different test scenarios, supporting the behavior of the simulated interface to be driven by a dynamic data source, and enabling more flexible and efficient interface testing and development work.

[0093] Based on the same inventive concept, an interface dynamic simulation device is also provided in the embodiments of the present disclosure, as described in the following embodiments. Since the principle of solving problems in this device embodiment is similar to that of the above method embodiment, the implementation of this device embodiment can refer to the implementation of the above method embodiment, and the repeated parts will not be elaborated.

[0094] Figure 4 Show a schematic diagram of an interface dynamic simulation device in the embodiments of the present disclosure, as Figure 4 shown, the interface dynamic simulation device 4 includes: a request interception module 401, a response generation module 402, and a request-response module 403;

[0095] The request interception module 401, in response to the probe injecting into the target interface of the server, intercepts the target request sent by the client to the server based on the probe.

[0096] In one embodiment, the request interception module 401 includes a probe injection module, and injects the probe into the target interface of the server based on at least one of methods such as modifying the bytecode of the server and creating a new proxy class using a bytecode operation library.

[0097] In one embodiment, the request interception module 401 includes a probe interception module. In response to a probe injecting into a target interface of the server, the probe intercepts a target request sent by the client to the server based on at least one interception method such as aspect-oriented programming technology and interceptor technology.

[0098] The response generation module 402 generates a dynamic simulation response through the probe according to dynamic configuration data; wherein, the dynamic configuration data is data for dynamically configuring a simulation interface.

[0099] In one embodiment, the response generation module 402 includes a first configuration module for dynamically configuring the dynamic configuration data through a configuration file.

[0100] In one embodiment, the response generation module 402 includes a second configuration module for dynamically configuring the dynamic configuration data by adding a custom annotation to the target interface.

[0101] In one embodiment, the response generation module 402 includes a third configuration module for dynamically configuring the dynamic configuration data by interacting with a dynamic data source.

[0102] In one embodiment, the response generation module 402 includes a simulation response module for generating a dynamic simulation response based on at least one of the dynamic configuration data and preset static data.

[0103] The request response module 403 sends the dynamic simulation response to the server so that the server generates a target response based on the dynamic simulation response for responding to the target request of the client.

[0104] In the above embodiments, by using a Java probe to inject into the application server and intercept HTTP requests, the ability of dynamic HTTP interface simulation is achieved. The behavior and response of the simulation interface, that is, the path, request method, request headers, request body, etc. of the simulation interface, are flexibly defined through configuration, and the corresponding simulation response is specified; and through dynamic data driving, the simulation response can be generated according to real-time data, so as to simulate different test scenarios; there is no need to restart the application, no need to modify the source code of the host application, protecting the stability and security of the application, and improving the efficiency and flexibility of interface testing, providing fast and reliable integration testing.

[0105] Figure 5 The flowchart of another interface dynamic simulation method in the embodiments of the present disclosure is shown. As Figure 5 shown, the interface dynamic simulation method provided in the embodiments of the present disclosure includes the following steps:

[0106] S502, Probe injection: Using Java probe technology, inject the probe into the server of the application; this can be achieved through bytecode injection or using a specific proxy mode.

[0107] 1) Use bytecode injection: Bytecode manipulation libraries (such as ASM, Javassist) can be used to modify the bytecode of the application server side and insert probe code into the methods of the target interface.

[0108] 2) Use the proxy pattern: Create a proxy class that implements the target interface and adds probe code to the methods; then, use this proxy class in the application to replace the original interface implementation.

[0109] S504, Interface interception: Once the probe is successfully injected, it will intercept the HTTP requests sent by the client of the application; this can be achieved by using Java's AOP (Aspect-Oriented Programming) technology or interceptors.

[0110] 1) Use AOP: Use Java's AOP frameworks (such as AspectJ, Spring AOP) to intercept before and after the execution of the methods of the target interface and execute the corresponding probe logic.

[0111] 2) Use interceptors: Use Java's Servlet filters or Spring's interceptors to intercept HTTP requests and execute the probe logic in the interceptors.

[0112] It should be noted that the probe logic includes but is not limited to: the logic of intercepting HTTP requests sent by the client of the application, the logic of encapsulating and returning dynamic mock responses, etc.

[0113] S506, Dynamic configuration: The probe allows developers to dynamically define the behavior of the mock interface at runtime through configuration files or other means; this includes setting the path of the interface, request method, request headers, request body, etc., and specifying the corresponding mock responses.

[0114] 1) Use configuration files: Define the behavior of the mock interface by reading configuration files (such as xml, json, properties), including information such as the path of the interface, request method, request headers, request body, and mock responses.

[0115] 2) Use annotations: Add custom annotations to the methods of the target interface and obtain and apply the configuration information of the mock interface by parsing the annotations.

[0116] 3) Use dynamic data sources such as ZooKeeper or Etcd: Store the configuration information of the mock interface in ZooKeeper, Etcd, or other distributed configuration centers. The probe code interacts with the dynamic data source to dynamically obtain the configuration information of the interface, and generates and processes the corresponding mock responses according to the dynamically obtained configuration information.

[0117] S508, Simulation Response: According to the configuration, the probe will generate a simulated HTTP response to replace the actual interface call. The simulation response can be predefined static data or dynamic data obtained from external data sources.

[0118] 1) Static Data: Hardcode predefined simulated response data in the probe code. For example, create a simulated response object and set the corresponding status code, response headers, and response body, etc.

[0119] 2) Dynamic Data: Obtain real-time data from external data sources (such as databases, file systems, network services) and use it for generating the simulation response. Relevant Java libraries and APIs can be used to implement the interaction with the data source.

[0120] S510, Data-driven: To achieve dynamic simulation, the probe supports obtaining real-time data from external data sources and using it for the simulation response. This can be achieved by interacting with databases, file systems, network services, etc.

[0121] 1) Select an appropriate data source (such as a database, file system, network service) as needed to store and obtain dynamic data. Through the interaction with the data source, use the real-time data for generating the simulation response.

[0122] 2) Use relevant Java libraries and APIs (such as JDBC, file I / O, network request libraries) to interact with the data source, obtain the required data, and apply it to the generation of the simulation response.

[0123] S512, Scalability: This technical solution provides a flexible extension mechanism that allows developers to add custom plugins or extension points as needed. This can implement additional functions such as request logging, assertion verification, performance analysis, etc.

[0124] 1) Add Custom Plugins: Define and implement a custom plugin interface. Developers can add custom plugins as needed to extend the functions of the probe, such as request logging, assertion verification, performance analysis, etc.

[0125] 2) Define Extension Points: By defining an extension point interface and the corresponding implementation classes, developers can register and call these extension points in the probe to implement additional functions.

[0126] In the above embodiments, through features such as dynamic configuration distribution, reduced invasiveness, data-driven, and custom extension, a more flexible, efficient, and scalable interface Mock solution is provided, which can quickly perform interface testing and integration testing, improving the efficiency and quality of software development.

[0127] Based on the same inventive concept, an interface dynamic simulation system is also provided in the embodiments of the present disclosure, as described in the following embodiments. Since the principle of problem-solving in this system embodiment is similar to that of the above method embodiment, the implementation of this system embodiment can refer to the implementation of the above method embodiment, and the repeated parts will not be described again.

[0128] Figure 6 A schematic diagram of an interface dynamic simulation system in an embodiment of the present disclosure is shown, as Figure 6 shown, the system includes: a server 602, a client 601, and a probe 603. Taking the number of the server 602 and the client 601 as n as an example.

[0129] In response to the injection of the Java probe of the probe 603 into the HTTP interface of the server 602, intercept the HTTP request sent by the client 601 to the server 602 based on the Java probe; generate a dynamic simulation mock response according to the dynamic configuration data through the probe; wherein, the dynamic configuration data is data for dynamically configuring the simulation interface; send the dynamic simulation response to the server 602, so that the server 602 encapsulates and processes the dynamic simulation response to generate a target response for responding to the HTTP request of the client 601.

[0130] In the probe 603, the dynamic configuration data is configured through dynamic configuration methods such as configuration files, adding custom annotations to target interfaces, and interacting with dynamic data sources; wherein, the dynamic data source is a database, a file system, an external network service, a distributed configuration center, a dynamic configuration remote source, an external data source, etc. that stores the dynamic configuration data of the simulation interface.

[0131] 1) Traditional interface Mock solutions usually require static configuration, that is, before the application starts, the behaviors and responses of the Mock interfaces are pre-configured; in the embodiments of the present disclosure, by using a distributed configuration center (such as ZooKeeper, Etcd, etc.) or other real-time configuration push mechanisms, developers can modify the configuration information of the Mock interfaces in real time, including paths, request methods, request headers, request bodies, and simulation responses, etc. The probe code will obtain the latest configuration from the configuration center regularly or in real time and apply it to the Mock interfaces; this way of dynamically distributing configurations greatly shortens the cycle for the configuration modification to take effect, enabling the configuration of the Mock interfaces to be dynamically modified during runtime, allowing developers to more flexibly adjust the behaviors and responses of the Mock interfaces to adapt to different test scenarios and requirements without restarting the application.

[0132] 2) Traditional interface Mock solutions usually require modifying the source code of the host application to intercept and process HTTP requests. In the embodiments of the present disclosure, the probe code redirects the intercepted HTTP requests to the Mock interface through aspect or bytecode technology, and generates corresponding mock responses according to the dynamically issued configuration information, realizing the ability to intercept and process HTTP requests without modifying the source code of the host application, which can minimize the intrusion into the host application, does not affect the normal operation of the application, and makes full use of the resources of the host application. This intrusion reduction solution enables this technology to be widely applicable to various applications, and applications based on Spring, JavaEE, or other frameworks and technology stacks can be easily integrated and used.

[0133] 3) Support data-driven and customer-defined extensions. That is, the behavior and responses of the Mock interface are driven by configured data. Developers can customize the configuration data according to actual needs, including paths, request methods, request headers, request bodies, and mock responses, etc. This data-driven design makes the behavior and responses of the Mock interface more flexible and extensible, and can meet different test scenarios and requirements. Developers can customize and extend the functions and behaviors of the Mock interface according to specific business logics and test requirements, and are allowed to add custom plugins or extension points as needed, so that additional functions and features can be added to the Java probe to meet the needs of different projects and teams.

[0134] The network is a medium for providing a communication link between the client 601, the server 602, and the probe 603, which can be a wired network or a wireless network.

[0135] Optionally, the above-mentioned wireless network or wired network uses standard communication technologies and / or protocols. The network is usually the Internet, but can also be any network, including but not limited to any combination of a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a mobile, wired or wireless network, a private network or a virtual private network. In some embodiments, technologies and / or formats including Hyper Text Mark-up Language (HTML), Extensible Markup Language (XML), etc. are used to represent data exchanged through the network. In addition, conventional encryption technologies such as Secure Socket Layer (SSL), Transport Layer Security (TLS), Virtual Private Network (VPN), Internet Protocol Security (IPsec), etc. can be used to encrypt all or some of the links. In other embodiments, customized and / or dedicated data communication technologies can also be used to replace or supplement the above data communication technologies.

[0136] The client 601 can be various electronic devices, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, wearable devices, augmented reality devices, virtual reality devices, etc.

[0137] Optionally, the clients 601 of the application programs installed in different clients 601 are the same, or are clients 601 of the same type of application program based on different operating systems. Depending on the different terminal platforms, the specific form of the client 601 of the application program can also be different. For example, the client 601 of the application program can be a mobile phone client 601, a PC client 601, etc.

[0138] The server corresponding to the server 602 can be a server that provides various services, such as a background management server that supports the devices for the operations performed by the user using the client 601. The background management server can analyze and process data such as requests received, and feedback the processing results to the client 601.

[0139] Optionally, the server can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The terminal and the server can be directly or indirectly connected through wired or wireless communication methods, and this application does not make any restrictions here.

[0140] Those skilled in the art can know that Figure 6 the numbers of the client 601, the probe end 603, and the server end 602 in

[0141] are merely illustrative. According to actual needs, there can be any number of clients 601, networks, and servers. The embodiments of the present disclosure do not make any limitations in this regard.

[0142] Those skilled in the art to which the present disclosure pertains can understand that various aspects of the present disclosure can be implemented as a system, a method, or a program product. Therefore, various aspects of the present disclosure can be specifically implemented in the following forms, namely: a complete hardware implementation manner, a complete software implementation manner (including firmware, microcode, etc.), or an implementation manner combining hardware and software aspects, which can be collectively referred to as "circuit", "module", or "system" here.

[0143] Next, refer to Figure 7 to describe the electronic device 700 according to this embodiment of the present disclosure. Figure 7 The electronic device 700 shown is merely an example and should not bring any limitations to the functions and usage scopes of the embodiments of the present disclosure.

[0144] As Figure 7 shown, the electronic device 700 is presented in the form of a general-purpose computing device. The components of the electronic device 700 may include, but are not limited to: at least one of the above-mentioned processing units 710, at least one of the above-mentioned storage units 720, and a bus 730 that connects different system components (including the storage unit 720 and the processing unit 710).

[0145] Among them, the storage unit stores program code, and the program code can be executed by the processing unit 710, so that the processing unit 710 executes the steps according to various exemplary embodiments of the present disclosure described in the above "Exemplary Method" section of this specification.

[0146] For example, the processing unit 710 may execute the following steps of the above method embodiment: in response to a target interface of the probe injection server, the probe intercepts a target request sent by the client to the server based on at least one of aspect-oriented programming technology and interceptor technology, generates a dynamic simulation response according to the dynamic configuration data through the probe, and sends the dynamic simulation response to the server, so that the server generates a target response according to the dynamic simulation response for responding to the target request of the client.

[0147] The storage unit 720 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 7201 and / or a cache storage unit 7202, and may further include a read-only storage unit (ROM) 7203.

[0148] The storage unit 720 may further include a program / utilities 7204 having a set (at least one) of program modules 7205. Such program modules 7205 include, but are not limited to: an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment.

[0149] The bus 730 may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus structures.

[0150] The electronic device 700 can also communicate with one or more external devices 740 (such as a keyboard, a pointing device, a Bluetooth device, etc.), and can also communicate with one or more devices that enable a user to interact with the electronic device 700, and / or communicate with any device that enables the electronic device 700 to communicate with one or more other computing devices (such as a router, a modem, etc.). Such communication can be carried out through the input / output (I / O) interface 750. Moreover, the electronic device 700 can also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through the network adapter 760. As shown in the figure, the network adapter 760 communicates with other modules of the electronic device 700 through the bus 730. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in combination with the electronic device 700, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.

[0151] Through the description of the above embodiments, those skilled in the art can easily understand that the exemplary embodiments described herein can be implemented by software or by a combination of software and necessary hardware. Therefore, the technical solutions according to the embodiments of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.

[0152] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided. The computer-readable storage medium can be a readable signal medium or a readable storage medium. A program product capable of implementing the above method of the present disclosure is stored thereon. In some possible implementation manners, various aspects of the present disclosure can also be implemented in the form of a program product, which includes program code. When the program product runs on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present disclosure described in the "Exemplary Method" section of this specification.

[0153] For example, when the program product in the embodiment of the present disclosure is executed by a processor, a method implementing the following steps is provided: in response to a probe injecting into a target interface of a server, the probe intercepts a target request sent by a client to the server based on at least one of aspect-oriented programming technology and interceptor technology, generates a dynamic simulation response according to dynamic configuration data through the probe, and sends the dynamic simulation response to the server, so that the server generates a target response according to the dynamic simulation response for responding to the target request of the client.

[0154] More specific examples of the computer-readable storage medium in the present disclosure may include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above.

[0155] In the present disclosure, the computer-readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, in which the readable program code is carried. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable signal medium may also be any readable medium other than the readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0156] Optionally, the program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination of the above.

[0157] In specific implementation, the program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and also including conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, executed as a stand-alone software package, partially on the user computing device and partially on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., by connecting through the Internet using an Internet service provider).

[0158] It should be noted that although several modules or units of the devices for action execution are mentioned in the above detailed description, such a division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more of the above-described modules or units may be embodied in one module or unit. Conversely, the features and functions of one module or unit described above may be further divided and embodied by multiple modules or units.

[0159] In addition, although the various steps of the methods in this disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in that specific order, or that all of the steps shown must be performed to achieve the desired result. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step for execution, and / or one step may be decomposed into multiple steps for execution, etc.

[0160] From the description of the above embodiments, those skilled in the art can easily understand that the example embodiments described herein can be implemented by software, or by a combination of software and necessary hardware. Therefore, the technical solutions according to the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the methods according to the embodiments of this disclosure.

[0161] After considering the specification and practicing the invention disclosed herein, those skilled in the art will readily conceive of other embodiments of this disclosure. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include known common general knowledge or conventional technical means in the technical field not disclosed in this disclosure. The specification and the embodiments are only regarded as exemplary, and the true scope and spirit of this disclosure are pointed out by the appended claims.

Claims

1. An interface dynamic simulation method, characterized in that, Including: In response to a probe injecting into a target interface of a server, intercepting a target request sent by a client to the server based on the probe; Generating a dynamic simulation response by the probe according to dynamic configuration data; wherein the dynamic configuration data is data for dynamically configuring a simulation interface; Sending the dynamic simulation response to the server, so that the server generates a target response according to the dynamic simulation response for responding to the target request of the client.

2. The interface dynamic simulation method according to claim 1, wherein The dynamic configuration method of the dynamic configuration data includes at least one of the following: Dynamically configuring the dynamic configuration data through a configuration file; Dynamically configuring the dynamic configuration data by adding a custom annotation to the target interface; Dynamically configuring the dynamic configuration data by interacting with a dynamic data source.

3. The interface dynamic simulation method according to claim 2, wherein The dynamic configuration data includes at least one of: interface path, request method, request header, request body, simulation response.

4. The interface dynamic simulation method according to claim 2 or 3, characterized in that, Also including: Generating the dynamic simulation response according to at least one of the dynamic configuration data and preset static data.

5. The interface dynamic simulation method according to claim 1, wherein The intercepting, in response to a probe injecting into a target interface of a server, a target request sent by a client to the server based on the probe includes: In response to the probe injecting into the target interface of the server, intercepting the target request sent by the client to the server by the probe based on at least one of aspect-oriented programming technology and interceptor technology.

6. The interface dynamic simulation method according to claim 1, characterized in that The injection method of the probe injecting into the target interface of the server includes at least one of the following: Modifying the bytecode of the server based on a bytecode operation library and inserting probe code into the method of the target interface; Applying a newly created proxy class to implement adding probe code in the method of the target interface.

7. The interface dynamic simulation method according to claim 1, characterized in that, Also including: Extending the function of the probe by adding at least one of a custom plug-in and a defined extension point to the target interface by the probe, wherein the function of the probe includes at least one of: request log recording, assertion verification, performance analysis.

8. An interface dynamic simulation device, characterized in that Including: A request interception module that, in response to a probe injecting into a target interface of a server, intercepts a target request sent by a client to the server based on the probe; A response generation module that generates a dynamic simulation response by the probe according to dynamic configuration data; wherein the dynamic configuration data is data for dynamically configuring a simulation interface; A request response module that sends the dynamic simulation response to the server, so that the server generates a target response according to the dynamic simulation response for responding to the target request of the client.

9. An electronic device, characterized in that, Including: A processor; And A memory for storing executable instructions of the processor; Wherein, the processor is configured to execute the interface dynamic simulation method according to any one of claims 1 to 7 by executing the executable instructions.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, The computer program, when executed by a processor, implements the interface dynamic simulation method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Interface response method and device, electronic equipment and storage medium

    CN120492054A

  • An interface response method, apparatus, electronic device, and storage medium

    CN120492054B