Mock service method and system, electronic equipment and storage medium
The mock configuration information of the target interface is obtained and stored through the front-end interface, which solves the problem of complex operation of the mock function in the existing technology, and realizes a simple and easy-to-use mock service.
Patent Information
- Application Number
- CN202411681595.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-04-25
AI Technical Summary
The method of implementing the mock function in the prior art is complex to operate, and requires relying on the Java environment and performing multi-step configuration and installation work.
Get the mock configuration information of the target interface through the front-end setting interface and store it in the database to provide simple and easy-to-use mock services. This method supports the desired configuration mode and custom script mode, separated from file and rule semantic definitions.
It realizes the simplicity and ease of use of mock services, reduces operational complexity, and improves the operability of mock services.
Smart Images

Figure CN119883396A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of mock function technology, and in particular to a mock service method, system, electronic equipment and storage medium. Background Art
[0002] The server-side interface mock function is used to simulate the behavior of the backend server returning data in the interface test. It is often used in scenarios where front-end and back-end developers do coupling and mediation, testers do interface testing, and third-party API calls need to be independent of environmental dependencies. Currently, the common method to implement the server-side mock function is to use third-party mock tools, such as MockServer, WireMock, Mockito, PowerMock, soapUI, EasyMock, etc. These tools can support protocols such as http / https / ws / soap, support high concurrency / distributed environments, support plug-in expansion / integration services, etc. The advantage is that it is powerful and can be used in various complex scenarios.
[0003] However, the use of third-party mock tools requires reliance on the Java environment, requires more configuration and installation work, and requires understanding of configuration definitions and mock rule semantics. Therefore, the methods for implementing mock functions in the prior art are complex to operate. Summary of the invention
[0004] The present invention provides a mock service method, system, electronic device and storage medium, which are used to solve the defect of complex operation of the method for realizing the mock function in the prior art. The mock response configuration of the server is performed through the front-end setting interface, which can be separated from the file and various rule semantic definitions, so as to realize the mock service providing method which is simple, easy to use and has strong operability.
[0005] The present invention provides a mock service method, comprising the following steps.
[0006] Acquire the mock configuration information corresponding to the target interface through the mock configuration interface, and store the mock configuration information in the database, wherein the mock configuration information includes multiple configuration fields and the values corresponding to each configuration field; A mock service is provided according to the mock configuration information stored in the database.
[0007] According to a mock service method provided by the present invention, the mock configuration information corresponding to the target interface is obtained through the mock configuration interface, and the mock configuration information is stored in a database, including: determining the target interface; The mock configuration information is obtained through the interface corresponding to the expected configuration mode or the custom script mode, and the mock configuration information is synchronized to the database. The expected configuration mode is used to indicate the method of obtaining the mock configuration information based on the input condition information, and the custom script mode is used to indicate the method of obtaining the mock configuration information based on the input script information.
[0008] According to a mock service method provided by the present invention, the step of obtaining the mock configuration information through an interface corresponding to an expected configuration mode or a custom script mode includes: Display a configuration details interface, wherein the configuration details interface includes a radio button, and the radio button is used to select the desired configuration mode or the custom script mode; When the radio control selects the desired configuration mode or the custom script mode, a corresponding information input box and a configuration generation control are displayed; When receiving the information that the configuration generation control is triggered, a response body content is generated according to the information in the information input box, and the response body content is the mock configuration information.
[0009] According to a mock service method provided by the present invention, when the radio button is selected as the expected configuration mode, the information input box includes an expected condition input box and a return data input box, the expected condition input box is used to input the expected condition of the request data for the target interface, and the return data input box is used to input specific response data corresponding to the request data.
[0010] According to a mock service method provided by the present invention, when the custom script mode is selected in the radio button, the information input box includes a script input box, the script input box is used to input script information including expected conditions for request data of the target interface and specific response data corresponding to the request data, and the configuration generation control includes a script test control, and the script test control is used to perform format verification on the entered script information.
[0011] According to a mock service method provided by the present invention, the determining the target interface includes: The target interface is determined by selecting an interface, or by entering an interface. The interface selection method is used to indicate that the target interface is obtained by screening all imported interfaces, and the interface entry method is used to indicate that a new interface is added and the interface information of the new interface is entered to obtain the target interface.
[0012] According to a mock service method provided by the present invention, the step of determining the target interface by selecting an interface includes: Display an interface document interface, wherein the interface document interface includes a document input box and a parsing control; When receiving the information that the parsing control is triggered, the interface document input in the document input box is parsed to obtain the corresponding interface; The target interface is determined according to the corresponding interface.
[0013] According to a mock service method provided by the present invention, the step of determining the target interface according to the corresponding interface includes: If the corresponding interface only includes the target interface, determining the corresponding interface as the target interface; If the corresponding interface includes multiple interfaces, the corresponding interfaces are screened according to the interface information to obtain the target interface.
[0014] According to a mock service method provided by the present invention, the step of determining the target interface by entering an interface includes: Displaying a response configuration homepage, wherein the response configuration homepage includes adding controls; In case of receiving the information that the adding control is triggered, displaying an information input box and a saving control, wherein the information input box is used to fill in the interface information of the target interface, and the saving control is used to store the input interface information; When receiving the information that the save control is triggered, the interface information in the information input box is saved to obtain the target interface.
[0015] According to a mock service method provided by the present invention, the method further includes: Perform mock response verification on the target interface according to the mock configuration information, Display a configuration details interface, wherein the configuration details interface includes a debugging function button corresponding to the target interface, and the debugging function button is used to verify the mock response configuration corresponding to the target interface; When receiving a message that the debugging function button is triggered, displaying a debugging window, wherein the debugging window displays interface information and request data corresponding to the target interface, as well as an online debugging button; When receiving the information that the online debugging button is triggered, the returned data is displayed in the debugging window, and the returned data is the data returned by the database according to the mock response configuration after the interface information and request data corresponding to the target interface are sent to the database.
[0016] According to a mock service method provided by the present invention, before displaying the interface information and request data corresponding to the target interface in the debugging window, the method further includes: Loading interface information corresponding to the target interface; The request data is obtained according to the mock response configuration corresponding to the target interface, and the request address and request port in the request data are set as the address and port of the mock server.
[0017] According to a mock service method provided by the present invention, the method further includes: Displaying a response configuration homepage, the response configuration homepage includes a check box control, an enable selected control, and a disable selected control, the check box control is used to select an interface, the enable selected control is used to start the selected interface, and the disable selected control is used to disable the selected interface; When receiving the trigger of the enable selected control, starting processing of the interface selected by the check box control; When receiving the triggering of the disable selected control, the interface selected by the check box control is disabled.
[0018] According to a mock service method provided by the present invention, providing a mock service according to the mock configuration information stored in the database includes: When receiving target request data, determining a mock configuration mode of the target interface corresponding to the target request data; When the mock configuration mode is the expected configuration mode, a mocked request data value is generated according to the parameter description, and the parameter description in the mocked request data value is removed to obtain target return data, wherein the parameter description is obtained according to the request body corresponding to the target interface; In the case where the mock configuration mode is a custom script mode, if the format of the entered script information meets the preset requirements, one of the result branches of the script information is determined to be the target return data; if the format of the entered script information does not meet the preset requirements, the error message is determined to be the return data.
[0019] The present invention also provides a mock service system, comprising the following modules: A service configuration module, used to obtain mock configuration information corresponding to the target interface through the mock configuration interface, and store the mock configuration information in a database, wherein the mock configuration information includes multiple configuration fields and values corresponding to each configuration field; A service providing module is used to provide mock services according to the mock configuration information stored in the database.
[0020] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned mock service methods when executing the computer program.
[0021] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the mock service method described above is implemented.
[0022] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the mock service method described above is implemented.
[0023] The mock service method, system, electronic device and storage medium provided by the present invention configure the mock response of the server through the front-end mock setting interface, can be separated from files and various rule semantic definitions, and realize the mock service providing method which is simple, easy to use and highly operable. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0025] Figure 1 It is a flowchart of the mock service method provided by the present invention.
[0026] Figure 2 This is one of the flow charts of the mock response configuration method provided by the present invention.
[0027] Figure 3 It is a schematic diagram of the interface of the Mock configuration mode provided by the present invention.
[0028] Figure 4 It is a schematic diagram of the interface generated by the response body provided by the present invention.
[0029] Figure 5 It is a schematic diagram of the interface of the script configuration mode provided by the present invention.
[0030] Figure 6 It is a schematic diagram of the script debugging interface provided by the present invention.
[0031] Figure 7 It is a schematic diagram of the interface of selecting a target interface provided by the present invention.
[0032] Figure 8 It is a schematic diagram of the interface of the search target interface provided by the present invention.
[0033] Fig. 9 It is a schematic diagram of the advanced mock input interface provided by the present invention.
[0034] Fig.10 It is a schematic diagram of interfaces corresponding to different interfaces provided by the present invention.
[0035] Fig.11 It is a schematic diagram of the interface of the input target interface provided by the present invention.
[0036] Fig.12 It is a schematic diagram of the advanced mock input interface provided by the present invention.
[0037] Fig.13 This is the second flow chart of the method for performing mock response configuration provided by the present invention.
[0038] Fig.14 It is a schematic diagram of the interface of the method for performing mock environment debugging provided by the present invention.
[0039] Fig.15 It is a schematic diagram of the online debugging window of the restful interface provided by the present invention.
[0040] Fig.16 It is a schematic diagram of the interface of the online debugging method of the Soap interface provided by the present invention.
[0041] Fig.17 It is a schematic diagram of the interface of the mock configuration switch provided by the present invention.
[0042] Fig.18 It is a scenario diagram of the mock service method provided by an embodiment of the present invention.
[0043] Fig.19 It is a logic diagram of the front-end and back-end mock interaction provided by the present invention.
[0044] Fig. 20 It is an architecture diagram of the mock service system provided by the present invention.
[0045] Fig.21 It is a schematic diagram of the structure of the mock service system provided by an embodiment of the present invention.
[0046] Fig. 22 A schematic diagram of the physical structure of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] The server-side interface mock function is used to simulate the behavior of the backend server returning data in the interface test. It is often used in scenarios where front-end and back-end developers do coupling and mediation, testers do interface testing, and third-party API calls need to be independent of environmental dependencies. Currently, the common method to implement the server-side mock function is to use third-party mock tools, such as MockServer, WireMock, Mockito, PowerMock, soapUI, EasyMock, etc. These tools can support protocols such as http / https / ws / soap, support high concurrency / distributed environments, support plug-in expansion / integration services, etc. The advantage is that it is powerful and can be used in various complex scenarios.
[0049] However, the use of third-party mock tools requires reliance on the Java environment, requires more configuration and installation work, and requires understanding of configuration definitions and mock rule semantics. Therefore, the methods for implementing mock functions in the prior art are complex to operate.
[0050] In view of this, an embodiment of the present invention provides a mock service method, which obtains mock configuration information corresponding to a target interface through a mock configuration interface, and stores the mock configuration information in a database; and provides a mock service according to the mock configuration information stored in the database. The method can be separated from files and various rule semantic definitions, and realizes a simple, easy-to-use and highly operable mock service provision method.
[0051] The technical solutions in the embodiments of the present invention will be described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0052] Figure 1 : is a flowchart of the mock service method provided by the present invention. The mock service method can be applied to a system that provides mock services. The system can be an electronic device. The electronic device can be various types of devices with information processing capabilities during implementation. For example, the electronic device can include a personal computer, a notebook computer, a palmtop computer or a server. Figure 1 As shown, the method may include the following steps 101 to 102: Step 101: Acquire mock configuration information corresponding to a target interface through a mock configuration interface, and store the mock configuration information in a database, wherein the mock configuration information includes a plurality of configuration fields and values corresponding to each configuration field.
[0053] It should be noted that the mock service platform / system can set a mock configuration interface for mock response configuration. The mock response configuration set through the mock configuration interface can be stored in a database. The mock response configuration can include multiple configuration fields and values corresponding to each configuration field.
[0054] Among them, there are many ways to obtain the mock configuration information corresponding to the target interface through the mock configuration interface and store the mock configuration information in the database, for example, Python language settings can be used, etc. The present invention does not limit the way to obtain the mock configuration information corresponding to the target interface through the mock configuration interface and store the mock configuration information in the database.
[0055] Step 102: Providing mock services according to the mock configuration information stored in the database.
[0056] It should be noted that when performing a mock response, parameters can be extracted according to the request data and matched with the fields in the mock response configuration stored in the database to determine the corresponding response data.
[0057] There are many ways to provide mock services according to the mock configuration information stored in the database, such as field matching, etc. The present invention does not limit the way to provide mock services according to the mock configuration information stored in the database.
[0058] Exemplarily, the server-side mock function can be implemented in combination with the interface management module on the automated test platform. For example, the front-end mock configuration management and maintenance can be performed on the restful interface defined in the swagger document and the soap interface defined in the wsdl document. When debugging the interface, the specific response data can be obtained by modifying the request address to the mock service address. The present invention achieves the purpose of obtaining a specific response when the back-end requests a specific interface in the mock environment by performing mock configuration management on the target interface in the front-end configuration details interface.
[0059] The present invention uses the front-end configuration details interface to configure the server-side mock response, is separated from files and various rule semantic definitions, can easily get started with mock rule configuration, and realizes the simplicity, ease of use and strong operability of the mock service provision method.
[0060] Figure 2This is one of the flow charts of the mock response configuration method provided by the present invention. Figure 2 As shown, obtaining the mock configuration information corresponding to the target interface through the mock configuration interface and storing the mock configuration information in the database may include: Step 201: Determine the target interface.
[0061] There are many methods for determining the target interface, such as analyzing the request data, determining it through interface information input by the user, or determining it through an interface document imported by the user. The present invention does not limit the method for determining the target interface.
[0062] Step 202: Acquire the mock configuration information through the interface corresponding to the expected configuration mode or the custom script mode, and synchronize the mock configuration information to the database, wherein the expected configuration mode is used to indicate a method for obtaining the mock configuration information based on input conditional information, and the custom script mode is used to indicate a method for obtaining the mock configuration information based on input script information.
[0063] It should be noted that the mock response configuration supports two modes: expected configuration mode and custom script mode. In the advanced mock entry interface, the field "level" supports two configuration modes (level): mock and script, where mock corresponds to the expected configuration mode and script corresponds to the custom script mode.
[0064] It can be understood that providing two configuration methods for mock response configuration can meet the multi-scenario response mock configuration of the same interface, which is more flexible and efficient.
[0065] In some embodiments, the step 202 obtains the mock configuration information through an interface corresponding to the expected configuration mode or the custom script mode, and may include: displaying a configuration details interface, the configuration details interface including a radio button, the radio button being used to select the expected configuration mode or the custom script mode; when the radio button is selected for the expected configuration mode or the custom script mode, displaying a corresponding information input box and a configuration generation control; when receiving information that the configuration generation control is triggered, generating a response body content according to the information in the information input box, the response body content being the mock configuration information.
[0066] It should be noted that by setting a configuration details interface, setting a radio button in the configuration details interface, and displaying a corresponding information input box and a configuration generation control after selecting the radio button, it is convenient for users to configure the mock response, making the mock response configuration more flexible and efficient.
[0067] Furthermore, when the radio button is selected to select the expected configuration mode, the information input box includes an expected condition input box and a return data input box, the expected condition input box is used to input the expected conditions for the request data of the target interface, and the return data input box is used to input specific response data corresponding to the request data.
[0068] Figure 3 Schematic diagram of the interface of the Mock configuration mode provided by the present invention. Figure 3 As shown in the figure, after selecting the mock configuration mode, the expected conditions and return data entry will be loaded. Adding the expected entry can enter the expected conditions for the interface request data, and the return data entry can enter specific response data for the interface response, including the response status code, head and body.
[0069] Adding expectations includes: (1) Parameters: the location of the target parameters, including query, path, head, body, and cookie; (2) Parameter name: the name of the target parameter. Nested request parameters are supported here through . to access attributes, e.g.: extension.entries[0].key; (3) Comparison: supported comparison operations, including existence, non-existence, greater than, less than, equal to, not equal to, contains, does not contain, is empty, is not empty; (4) Parameter value: comparison value. (5) Note: The expected condition entry can be empty or >= 1. The matching logic can refer to the mock matching logic.
[0070] The returned data includes: (1) HTTP status code: response status code, default is 200, and the exception status code can also be set to cover the exception scenario; (2) Head: custom Head response header, json format; (3) Body: custom Body response body, and also supports on-demand modification of automatically generated data; the format has the following differences: for restful interface: support json / xml / text text format; for soap interface: support soap protocol message format; (4) Note: The network exception mock entry is not provided yet. If needed, you can directly add this entry in the return data module to provide exception return mock, e.g. network delay, timeout, network disconnection, etc.
[0071] Figure 4 This is a schematic diagram of the interface generated by the response body provided by the present invention. Figure 4As shown, the target interface can be the interface parsed and entered by the platform. When the configuration rule level is selected as mock, the "auto generate" function will be provided. The function is to automatically parse and generate the response body according to the interface response parameter information defined in the swagger / wsdl document. The parameter value is the mock data generated according to the parameter description, which can be modified as needed based on the automatically generated default body data.
[0072] The body format is different: when the target interface is a restful interface, the automatically generated body is in json format. When the soap interface is a soap protocol message, the automatically generated body is in soap protocol message format.
[0073] Furthermore, when the custom script mode is selected in the radio button, the information input box includes a script input box, which is used to input script information including expected conditions for request data for the target interface and specific response data corresponding to the request data, and the configuration generation control includes a script test control, which is used to perform format verification on the entered script information.
[0074] Figure 5 Schematic diagram of the script configuration mode provided by the present invention. Figure 5 As shown, the page will provide the default data format of the script, which can be modified as needed (where req is a fixed reference to the request and res is a fixed reference to the response). It also supports nested request parameters through .Accessing properties, Eg: if "queryType" inreq.body.arg0.paymentKey and req.body.arg0.paymentKey.queryType== "penny01":res.response = {******}; Note: For restful interfaces, the res.response format maintained by the script is json / xml / text text format; for soap interfaces, the res.response format maintained by the script is soap protocol message format.
[0075] In some embodiments, determining the target interface may include: determining the target interface by selecting an interface, or determining the target interface by entering an interface, wherein the interface selection method is used to indicate that the target interface is obtained by screening among all imported interfaces, and the interface entry method is used to indicate that a new interface is added and the interface information of the new interface is entered to obtain the target interface.
[0076] It should be noted that the two methods of determining the target interface, namely, selecting an interface or entering an interface, can facilitate the user to determine the target interface for mock response configuration, making the method of determining the target interface more flexible and efficient.
[0077] Furthermore, determining the target interface by selecting an interface may include: displaying an interface document interface, the interface document interface including a document input box and a parsing control; upon receiving information that the parsing control is triggered, parsing the interface document input in the document input box to obtain a corresponding interface; and determining the target interface based on the corresponding interface.
[0078] Figure 6 Schematic diagram of the script debugging interface provided by the present invention. Figure 6 As shown, the format of the entered script is checked: if the format is correct, one of the results of the script entry res branch is returned. If there is a problem with the format, Error is returned, indicating that the statement is abnormal.
[0079] The relationship between the target interface and the mock configuration rule entry is a one-to-one or one-to-many relationship. For the specific mock matching logic, refer to the advanced mock matching logic.
[0080] Among them, determining the target interface based on the corresponding interface may include: if the corresponding interface only includes the target interface, determining the corresponding interface as the target interface; if the corresponding interface includes multiple interfaces, filtering the corresponding interface through interface information to obtain the target interface.
[0081] Figure 7 Schematic diagram of the interface for selecting a target interface provided by the present invention. Figure 7 As shown, the interface defined in the swagger / wsdl document is parsed and stored in the library: under the menu bar Interface Management->Interface Document, enter the business unit module, click Parse, and it will trigger the parsing of all interfaces defined in the corresponding swagger / wsdl document and store them in the library. Among them, the input business unit module has the following situations: 1. Only the restful interface defined in the swagger document, 2. Only the soap interface defined in the wsdl document, 3. Both the restful interface defined in the swagger document and the soap interface defined in the wsdl document. The interface for selecting the target interface provided by the present invention supports the import of multiple types of interfaces.
[0082] Figure 8 Schematic diagram of the interface of the search target interface provided by the present invention. Figure 8As shown in the figure, find the target interface by filtering the interface information, and then click the Advanced Mock button for the target interface to enter the Advanced Mock entry interface.
[0083] Fig. 9 Schematic diagram of the advanced mock input interface provided by the present invention. Fig. 9 As shown, the advanced mock input interface will automatically load the target interface information.
[0084] Fig.10 Schematic diagram of the interface corresponding to different interfaces provided by the present invention. Fig.10 As shown in the figure, when the target interface is a RESTful interface, the type field loaded is the request type of the RESTful interface: get / post / delete / put / patch / head / options. When the target interface is a SOAP interface, the type field loaded is the method defined in the WSDL document.
[0085] Furthermore, determining the target interface by inputting an interface may include: displaying a response configuration homepage, the response configuration homepage including an add control; upon receiving information that the add control is triggered, displaying an information input box and a save control, the information input box is used to fill in the interface information of the target interface, and the save control is used to maintain the input interface information; upon receiving information that the save control is triggered, saving the interface information in the information input box to obtain the target interface. The response configuration homepage is the advanced mock input homepage.
[0086] It can be understood that the mock service provided by the present invention can support the restful interface defined in the swagger document and the soap interface defined in the wsdl document, and has complete functions.
[0087] Fig.11 Schematic diagram of the interface for inputting a target interface provided by the present invention. Fig.11 As shown, under the menu bar Interface Management -> Advanced Mock, directly click the operation button "Advanced Mock" to enter the advanced mock entry page. At this time, you need to manually enter the target interface information.
[0088] Fig.12 Schematic diagram of the advanced mock input interface provided by the present invention. Fig.12As shown, the interface information includes name, code ZFcode, type, level, interface name and whether to start, etc. When the interface is a soap interface, the interface name needs to end with ?wsdl to mark the soap interface: Eg: / cxf-service / RefundRequestFacade?wsdl. For example, the interface name is the different interface paths of this service, which are used for different purposes. zf990 is the interface number, and auc_web is a code name of the service name.
[0089] Fig.13 This is the second flow chart of the method for configuring mock responses provided by the present invention. Fig.13 As shown, obtaining the mock configuration information corresponding to the target interface through the mock configuration interface and storing the mock configuration information in the database may include: Step 301: Determine the target interface.
[0090] Step 302: Acquire the mock configuration information through the interface corresponding to the expected configuration mode or the custom script mode, and synchronize the mock configuration information to the database, the expected configuration mode is used to indicate the method of obtaining the mock configuration information based on the input condition information, and the custom script mode is used to indicate the method of obtaining the mock configuration information based on the input script information.
[0091] Step 303: Perform mock response verification on the target interface according to the mock configuration information.
[0092] It should be noted that after completing the mock response configuration, the mock response configuration can be verified to determine whether the response data fed back when the request data is received is consistent with the expected data. The above method can further improve the accuracy of the mock service.
[0093] It can be understood that the mock service method runs the mock environment debugging to determine that the mock response data is consistent with expectations, so as to obtain a specific response when the backend requests a specific interface in the mock environment, thereby improving the accuracy of the mock response.
[0094] In some embodiments, step 303 performs mock response verification on the target interface according to the mock configuration information, and may include: displaying a configuration details interface, the configuration details interface including a debugging function button corresponding to the target interface, the debugging function button being used to verify the mock response configuration corresponding to the target interface; upon receiving a message that the debugging function button is triggered, displaying a debugging window, the debugging window displaying interface information and request data corresponding to the target interface, and an online debugging button; upon receiving a message that the online debugging button is triggered, displaying return data in the debugging window, the return data being data returned by the database according to the mock response configuration after the interface information and request data corresponding to the target interface are sent to the database.
[0095] Before displaying the interface information and request data corresponding to the target interface in the debugging window, the method may further include: loading the interface information corresponding to the target interface; obtaining the request data according to the mock response configuration corresponding to the target interface, and setting the request address and request port in the request data to the address and port of the mock server. The configuration details interface is the advanced mock details page.
[0096] Fig.14 Schematic diagram of the interface of the method for debugging the mock environment provided by the present invention. Fig.14 As shown in the figure, on the advanced mock homepage, check the mock configuration record of the maintained target interface. There is an "Online Debug" button in the corresponding operation column. After clicking "Online Debug", the debugging window will pop up in real time.
[0097] Fig.15 Schematic diagram of the online debugging window of the restful interface provided by the present invention. Fig.15 As shown, it includes port POST, request data and return data.
[0098] Fig.16 Schematic diagram of the interface of the online debugging method of the Soap interface provided by the present invention. Figure 6 As shown, it also includes port POST, request data and return data.
[0099] visible, Fig.15 and Fig.16 The POST information is not the same.
[0100] It should be noted that the debugging window includes three parts: the interface request resource location string url and request method, request data and return data.
[0101] Among them, the interface request url and request method: information loading of the target interface; request data: the real-time generation of request data is automatically generated according to the following logical scenarios based on our company's needs: If the target interface of the mock configuration is manually entered, the request data body is empty data; The target interface of this mock configuration is the platform storage selection, which is divided into the following scenarios: level=mock, if the expected condition entry is empty, the request data body is the mock data generated by interface parsing; level=mock, and the expected condition entry is not empty, the request data body is based on the mock data generated by the interface parsing, and is replaced with the expected parameter values specified by the expected condition; If level=script, the request data body is empty data; Return data: The return data is the specific response body after taking the request data, calling the target interface address in the mock environment (IP and port of the mock server), and performing logical matching according to the mock configuration entry on the platform. The matching logic here refers to the advanced mock matching logic.
[0102] In some embodiments, the method of obtaining mock configuration information corresponding to the target interface through the mock configuration interface and storing the mock configuration information in a database may also include: displaying a response configuration homepage, the response configuration homepage including a check box control, an enable selected control and a disable selected control; when the enable selected control is triggered, starting processing for the interface selected by the check box control; when the disable selected control is triggered, disabling processing for the interface selected by the check box control.
[0103] Fig.17 Schematic diagram of the interface of the mock configuration switch provided by the present invention. Fig.17 As shown, the advanced mock page supports turning on / off the mock configuration rules.
[0104] In some embodiments, step 102 provides mock services according to the mock configuration information stored in the database, and may include: when target request data is received, determining the mock configuration mode of the target interface corresponding to the target request data; when the mock configuration mode is the expected configuration mode, generating a mock request data value according to the parameter description, and removing the parameter description in the mock request data value to obtain target return data, wherein the parameter description is obtained according to the request body corresponding to the target interface; when the mock configuration mode is the custom script mode, if the format of the entered script information meets the preset requirements, determining that one of the result branches of the script information is the target return data, and if the format of the entered script information does not meet the preset requirements, determining that the error information is the return data.
[0105] In some embodiments, the backend provides three types of "response body automatic generation interfaces": The first is to provide an "automatic response body generation interface".
[0106] Function: Automatically generate response body to reduce manual configuration cost. This function is provided when the target interface selected on the platform is in "mock" configuration mode.
[0107] According to the following operation logic: find the request body of the target interface parsed and stored in the platform (including the parameter description defined in the swagger / wsdl document) -> generate the mock request data value in real time according to the parameter description -> remove the parameter description in the request body -> obtain the mock response Body.
[0108] The specific steps include: Step 1: Parse the document titrator interface request information to assemble the request body, including the description field of each parameter. Step 2: Generate mock parameter values in real time according to the description field of each parameter. Step 3: Finally, remove the parameter description field, get the request body after real-time mock, and use it directly for interface request.
[0109] The second is to provide a "custom script debugging interface".
[0110] Function: When the script configuration mode is selected, the format of the entered custom script is checked: if the format is correct, one of the res branches entered in the script is returned; if there is a problem with the format, Error is returned, indicating that the statement is abnormal.
[0111] The third is to provide "advanced mock real-time debugging interface".
[0112] Function: After making advanced mock configuration for the target interface, the interface can be debugged in real time to verify whether the mock configuration is effective and the configuration result.
[0113] Specifically, the mock debugging and verification are performed according to the following logic: Assemble the request body according to the details of this mock configuration, and the logic refers to the logic for generating request data. Set the request IP and port to the IP and port of the mock server, the request interface address to the target interface path, and the request parameters to the request body from the previous step. Obtain a specific mock response in real time and return it to the front end. The backend script for setting up the mock service is encapsulated in flask_dynamic.py. The script provides an interface service through the Flask framework, and the main logic implementation includes two parts.
[0114] Among them, 1. Parsing the request body and assembling mockRequest includes: 1) Matching the interface through the <path: variable name> wildcard method of the Flask framework; 2) Identifying restful / soap requests based on whether the request address has the suffix "?wsdl": For restful requests, directly obtain the request body data in JSON format (including head, path, query, body, file) as the mockRequest body; for soap requests, parse the soap protocol message and convert it into a mockRequest body in JSON format. 2. Matching and returning the mockResponse corresponding to the hit rule according to the advanced mock configuration.
[0115] Here, a target interface corresponds to N mock configuration entries. The mock configuration matching logic is as follows: 1) Search in the database for rule entries with level='mock' and status enabled: First, match the entries with non-empty expected conditions, sort them in ascending order of the entry input time, and return the mockResponse corresponding to the matching entry when the expected conditions are checked to match; Secondly, match the entries with empty expected conditions, sort them in ascending order of the entry input time, and return the mockResponse corresponding to the earliest entered entry; If there is no match, continue with the following steps; 2) Search in the database for rule entries with level='script' and status enabled: Verify that the number of entries corresponding to the target interface <= 1; Parse the script content of the mockResponse. If an exception occurs during script parsing (e.g., AttributeError), it is considered a mismatch. If the script is parsed normally, it is considered a match and the parsed mockResponse is returned; If there is no match, continue with the following steps; 3) Search for the rule entry with level='default' and status enabled in the database: Verify that the expected condition is empty, and then randomly return one of the corresponding mockResponses; If there is no match, continue with the following steps; 4) Generate the default rule entry with level='default': Generate two entries with level='default' according to the mapped keyword parameters, corresponding to the mock configuration names success and failure, and then randomly return one of the corresponding mockResponses.
[0116] It can be understood that the present invention combines the back-end python file with the jar package of the front-end springboot framework, so the environment deployment is simpler and the applicability is stronger.
[0117] The following describes an exemplary application of an embodiment of the present invention in a practical application scenario.
[0118] Fig.18 Schematic diagram of the mock service method provided by the present invention. Fig.18 As shown, it includes the steps of selecting / entering the target interface, entering the mock configuration, and debugging and running the mock environment.
[0119] Among them, the step of selecting / entering the target interface (supporting RESTful and SOAP interfaces) includes two situations. In the first situation, the interface has been entered into the platform. You can search for the target interface through the interface details page under the interface management module in the menu bar, and click the button "Advanced Mock" to jump to the mock entry interface. In the second situation, the interface has not been entered into the platform. On the advanced mock page under the interface management module in the menu bar, click the button "Advanced Mock" to jump to the mock entry interface. At this time, the target interface information needs to be manually entered on the page.
[0120] There are two configuration methods for entering mock configuration steps. Method 1 is mock mode, that is, you can add expected conditions through the "Add Expectation" entry; you can add expected returns through the "Return Data" entry. Method 2 is script mode, that is, you can add custom scripts through the "Script" entry.
[0121] The debugging and running steps of the mock environment include: cooperating with the mock rules to abandon / deactivate, and clicking "online debugging" to detect in real time whether the mock rules are effective.
[0122] Fig.19 It is a logic diagram of the front-end and back-end mock interaction provided by the present invention. Fig.19As shown in the figure, the front-end makes a specific mock configuration for the target interface through the platform and stores it in the library. During debugging and running, the front-end calls the interface support provided in the back-end script flask_support.py, and returns a specific mock result after running. Among them, calling the target interface of the mock environment and returning specific mock response data according to the mock configuration is achieved by calling the interface of the back-end script flask_dynamic.py.
[0123] Exemplarily, the devices and services involved in the present invention are deployed as follows: Web front-end server: Linux server, deploying the jar service of the automation platform based on the springboot framework. Back-end server: Linux server, deploying the back-end scripts flask_support.py and flask_dynamic.py related to interface management.
[0124] Fig. 20 This is the architecture diagram of the mock service system provided by the present invention. Fig. 20 As shown, the mock service system includes the advanced mock front-end, namely the mock configuration module, the mock service module and the database. Among them, the advanced mock front-end includes the mock list (main entry page): 1) List of all mocked interfaces: including display, filtering, paging, enabling, disabling and other functions. 2) Single mock interface: including online debugging: check whether the call result is as expected, editing: continue to edit expectations according to the online debugging results, deletion and other functions. 3) Add a new mock interface (configuration entry 1), by clicking the + sign, enter the mock details configuration page for configuration and then add. Configuration entry 2, including the interface details page, after filtering, find the target interface, click the + sign, enter the mock details configuration page. Among them, the mock details (level is mock), including 1) Check whether the interface name, type and other data are correct, 2) Select the level as mock, 3) Add expectations, 4) Set the return data, automatically generate response data according to the response format of the interface, repeat the automatic generation, and manually modify the response data, 5) Save and exit the details page (data is stored in the mysql database), 6) Return to the mock list page. Mock details (level is script), including 1) check whether the interface name, type and other data are correct, 2) select the level as script, 3) add Python script, 4) debug the script until there is no syntax error, 5) save and exit the details page (data is stored in MySQL database), 6) return to the mock list page. For the mock service (running), the main functions include: parsing the path, params and body values of the request to this service, matching the database response path record, and returning the response content stored in the record in the database.
[0125] The mock service method provided by the present invention configures the mock response of the server through the front-end page, is separated from files and various rule semantic definitions, can get started with mock rule configuration at zero cost, is simple, easy to use and has strong operability; and the mock response configuration supports two modes: the expected configuration mode and the custom script mode, which meet the multi-scenario response mock configuration of the same interface, and is more flexible and efficient; supports the restful interface defined by the swagger document and the soap interface defined by the wsdl document, and has complete functions; the back-end python file is combined with the jar package of the front-end springboot framework, and the environment deployment is simpler and more applicable.
[0126] Based on the foregoing embodiments, an embodiment of the present invention provides a mock service system, wherein each module included in the system and each unit included in each module can be implemented by a processor; of course, they can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP) or a field programmable gate array (FPGA), etc.
[0127] The mock service system provided by the present invention is described below. The mock service system described below and the mock service method described above can be referred to each other.
[0128] Fig.21 Schematic diagram of the structure of the mock service system provided by the embodiment of the present invention. Fig.21 As shown, the system 400 includes a service configuration module 401 and a service provision module 402, wherein: The service configuration module 401 is used to obtain the mock configuration information corresponding to the target interface through the mock configuration interface, and store the mock configuration information in the database, wherein the mock configuration information includes multiple configuration fields and the values corresponding to each configuration field; The service providing module 402 is used to provide mock services according to the mock configuration information stored in the database.
[0129] In some embodiments, the service configuration module 401 includes an interface determination unit and a service configuration unit, wherein: The interface determination unit is used to determine the target interface; The service configuration unit is used to obtain the mock configuration information through an interface corresponding to an expected configuration mode or a custom script mode, and synchronize the mock configuration information to the database. The expected configuration mode is used to indicate a method for obtaining the mock configuration information based on input conditional information, and the custom script mode is used to indicate a method for obtaining the mock configuration information based on input script information.
[0130] In some embodiments, the service configuration unit is specifically used to: display a configuration details interface, the configuration details interface includes a radio button, the radio button is used to select the desired configuration mode or the custom script mode; when the radio button is selected for the desired configuration mode or the custom script mode, display a corresponding information input box and a configuration generation control; when receiving information that the configuration generation control is triggered, generate a response body content according to the information in the information input box, and the response body content is the mock configuration information.
[0131] In some embodiments, the service configuration unit is also specifically used to: when the radio control is selected as the expected configuration mode, the information input box includes an expected condition input box and a return data input box, the expected condition input box is used to input the expected conditions for the request data of the target interface, and the return data input box is used to input specific response data corresponding to the request data.
[0132] In some embodiments, the service configuration unit is also specifically used to: when the radio button is selected in the custom script mode, the information input box includes a script input box, and the script input box is used to input script information including expected conditions for request data for the target interface and specific response data corresponding to the request data; the configuration generation control includes a script test control, and the script test control is used to perform format verification on the entered script information.
[0133] In some embodiments, the interface determination unit is specifically used to: determine the target interface by selecting an interface, or determine the target interface by entering an interface. The interface selection method is used to indicate that the target interface is obtained by screening from all imported interfaces, and the interface entry method is used to indicate adding a new interface and entering the interface information of the new interface to obtain the target interface.
[0134] In some embodiments, the interface determination unit is also specifically used to: display an interface document interface, the interface document interface including a document input box and a parsing control; upon receiving information that the parsing control is triggered, parsing the interface document input in the document input box to obtain a corresponding interface; and determining the target interface based on the corresponding interface.
[0135] In some embodiments, the interface determination unit is further specifically used to: if the corresponding interface only includes the target interface, determine the corresponding interface as the target interface; if the corresponding interface includes multiple interfaces, filter the corresponding interface through interface information to obtain the target interface.
[0136] In some embodiments, the interface determination unit is also specifically used to: display an interface document interface, the response configuration homepage includes an add control; when receiving information that the add control is triggered, display an information input box and a save control, the information input box is used to fill in the interface information of the target interface, and the save control is used to maintain the input interface information; when receiving information that the save control is triggered, save the interface information in the information input box to obtain the target interface.
[0137] In some embodiments, the device also includes a response verification module, which is used to: perform a mock response verification on the target interface according to the mock configuration information, and display a configuration details interface, wherein the configuration details interface includes a debugging function button corresponding to the target interface, and the debugging function button is used to verify the mock response configuration corresponding to the target interface; when a message that the debugging function button is triggered is received, a debugging window is displayed, and the debugging window displays interface information and request data corresponding to the target interface, as well as an online debugging button; when information that the online debugging button is triggered is received, return data is displayed in the debugging window, and the return data is data returned by the database according to the mock response configuration after the interface information and request data corresponding to the target interface are sent to the database.
[0138] In some embodiments, the response verification module is also used to: load interface information corresponding to the target interface; obtain request data according to the mock response configuration corresponding to the target interface, and set the request address and request port in the request data to the address and port of the mock server.
[0139] In some embodiments, the device also includes a response switch module, which is used to display a response configuration homepage, and the response configuration homepage includes a check box control, an enable selected control, and a disable selected control. The check box control is used to select an interface, the enable selected control is used to start the selected interface, and the disable selected control is used to disable the selected interface; when the enable selected control is triggered, the interface selected by the check box control is started; when the disable selected control is triggered, the interface selected by the check box control is disabled.
[0140] In some embodiments, the service provision module 402 is specifically used to: when receiving target request data, determine the mock configuration mode of the target interface corresponding to the target request data; when the mock configuration mode is the expected configuration mode, generate the mock request data value according to the parameter description, and remove the parameter description in the mock request data value to obtain the target return data, and the parameter description is obtained according to the request body corresponding to the target interface; when the mock configuration mode is the custom script mode, if the format of the entered script information meets the preset requirements, determine that one of the result branches of the script information is the target return data, if the format of the entered script information does not meet the preset requirements, determine that the error message is the return data.
[0141] In the embodiment of the present invention, the server-side mock response configuration is performed through the front-end setting interface, which can be separated from files and various rule semantic definitions, thereby realizing a simple, easy-to-use and highly operable mock service method.
[0142] Fig. 22 The physical structure diagram of the electronic device provided by the present invention is shown in FIG. Fig. 22 As shown, the electronic device 500 may include: a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502 and the memory 503 communicate with each other through the communication bus 504. The processor 501 may call the logic instructions in the memory 503 to execute the mock service method, which includes: obtaining the mock configuration information corresponding to the target interface through the mock configuration interface, and storing the mock configuration information in a database, wherein the mock configuration information includes a plurality of configuration fields and values corresponding to each configuration field; and providing a mock service according to the mock configuration information stored in the database.
[0143] In addition, the logic instructions in the above-mentioned memory 503 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0144] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the mock service method provided by the above methods, the method including: obtaining mock configuration information corresponding to the target interface through a mock configuration interface, and storing the mock configuration information in a database, the mock configuration information including multiple configuration fields and values corresponding to each configuration field; providing mock service according to the mock configuration information stored in the database.
[0145] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated therein. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0146] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the mock service method provided by the above methods, the method comprising: obtaining mock configuration information corresponding to the target interface through a mock configuration interface, and storing the mock configuration information in a database, the mock configuration information comprising multiple configuration fields and values corresponding to each configuration field; and providing mock service according to the mock configuration information stored in the database.
[0147] The above-mentioned computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, - but not limited to - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM) or flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0148] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0149] The program code embodied on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wire, optical cable, radio frequency (RF), etc., or any suitable combination of the foregoing.
[0150] Computer program code for performing the operations of the present specification may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0151] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0152] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0153] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A mock service method, characterized in that: include: Acquire the mock configuration information corresponding to the target interface through the mock configuration interface, and store the mock configuration information in the database, wherein the mock configuration information includes multiple configuration fields and the values corresponding to each configuration field; A mock service is provided according to the mock configuration information stored in the database.
2. The mock service method according to claim 1, characterized in that: The step of obtaining mock configuration information corresponding to the target interface through the mock configuration interface and storing the mock configuration information in a database includes: determining the target interface; The mock configuration information is obtained through the interface corresponding to the expected configuration mode or the custom script mode, and the mock configuration information is synchronized to the database. The expected configuration mode is used to indicate the method of obtaining the mock configuration information based on the input condition information, and the custom script mode is used to indicate the method of obtaining the mock configuration information based on the input script information.
3. The mock service method according to claim 2, characterized in that: The obtaining of the mock configuration information through the interface corresponding to the expected configuration mode or the custom script mode includes: Display a configuration details interface, wherein the configuration details interface includes a radio button, and the radio button is used to select the desired configuration mode or the custom script mode; When the radio control selects the desired configuration mode or the custom script mode, a corresponding information input box and a configuration generation control are displayed; When receiving the information that the configuration generation control is triggered, a response body content is generated according to the information in the information input box, and the response body content is the mock configuration information.
4. The mock service method according to claim 3, characterized in that: When the radio button is selected as the expected configuration mode, the information input box includes an expected condition input box and a return data input box, the expected condition input box is used to input the expected conditions for the request data of the target interface, and the return data input box is used to input specific response data corresponding to the request data.
5. The mock service method according to claim 3, characterized in that: When the custom script mode is selected in the radio button, the information input box includes a script input box, which is used to input script information including expected conditions for request data for the target interface and specific response data corresponding to the request data, and the configuration generation control includes a script test control, which is used to perform format verification on the entered script information.
6. The mock service method according to claim 2, characterized in that: The determining the target interface comprises: The target interface is determined by selecting an interface, or by entering an interface. The interface selection method is used to indicate that the target interface is obtained by screening all imported interfaces, and the interface entry method is used to indicate that a new interface is added and the interface information of the new interface is entered to obtain the target interface.
7. The mock service method according to claim 6, characterized in that: The step of determining the target interface by selecting an interface includes: Display an interface document interface, wherein the interface document interface includes a document input box and a parsing control; When receiving the information that the parsing control is triggered, the interface document input in the document input box is parsed to obtain the corresponding interface; The target interface is determined according to the corresponding interface.
8. The mock service method according to claim 7, characterized in that: The determining the target interface according to the corresponding interface includes: If the corresponding interface only includes the target interface, determining the corresponding interface as the target interface; If the corresponding interface includes multiple interfaces, the corresponding interface is screened according to the interface information to obtain the target interface.
9. The mock service method according to claim 6, characterized in that: The step of determining the target interface by inputting an interface comprises: Displaying a response configuration homepage, wherein the response configuration homepage includes adding controls; In case of receiving the information that the adding control is triggered, displaying an information input box and a saving control, wherein the information input box is used to fill in the interface information of the target interface, and the saving control is used to store the input interface information; When receiving the information that the save control is triggered, the interface information in the information input box is saved to obtain the target interface.
10. The mock service method according to claim 2, characterized in that: The method further comprises: Perform mock response verification on the target interface according to the mock configuration information, Display a configuration details interface, wherein the configuration details interface includes a debugging function button corresponding to the target interface, and the debugging function button is used to verify the mock response configuration corresponding to the target interface; When receiving a message that the debugging function button is triggered, displaying a debugging window, wherein the debugging window displays interface information and request data corresponding to the target interface, as well as an online debugging button; When receiving the information that the online debugging button is triggered, the returned data is displayed in the debugging window, and the returned data is the data returned by the database according to the mock response configuration after the interface information and request data corresponding to the target interface are sent to the database.
11. The mock service method according to claim 10, characterized in that: Before displaying the interface information and request data corresponding to the target interface in the debugging window, the method further includes: Loading interface information corresponding to the target interface; The request data is obtained according to the mock response configuration corresponding to the target interface, and the request address and request port in the request data are set as the address and port of the mock server.
12. The mock service method according to claim 2, characterized in that: The method further comprises: Displaying a response configuration homepage, the response configuration homepage includes a check box control, an enable selected control, and a disable selected control, the check box control is used to select an interface, the enable selected control is used to start the selected interface, and the disable selected control is used to disable the selected interface; When receiving the trigger of the enable selected control, starting processing of the interface selected by the check box control; When receiving the triggering of the disable selected control, the interface selected by the check box control is disabled.
13. The mock service method according to claim 1, characterized in that: The providing a mock service according to the mock configuration information stored in the database includes: When receiving target request data, determining a mock configuration mode of the target interface corresponding to the target request data; When the mock configuration mode is the expected configuration mode, a mocked request data value is generated according to the parameter description, and the parameter description in the mocked request data value is removed to obtain target return data, wherein the parameter description is obtained according to the request body corresponding to the target interface; In the case where the mock configuration method is a custom script mode, if the format of the entered script information meets the preset requirements, one of the result branches of the script information is determined to be the target return data; if the format of the entered script information does not meet the preset requirements, the error message is determined to be the return data.
14. A mock service system, characterized in that: include: A service configuration module, used to obtain mock configuration information corresponding to the target interface through the mock configuration interface, and store the mock configuration information in a database, wherein the mock configuration information includes multiple configuration fields and values corresponding to each configuration field; A service providing module is used to provide mock services according to the mock configuration information stored in the database.
15. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the mock service method according to any one of claims 1 to 13 is implemented.
16. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the mock service method according to any one of claims 1 to 13 is implemented.
17. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the mock service method according to any one of claims 1 to 13 is implemented.
Citation Information
Cited By
Interface test method, device and equipment for simulating third-party asynchronous system
CN121029627A