Mock testing method, device, electronic device and computer-readable storage medium

Through the combination of interception server and script engine, the problem of how to mock the front-end in front-end and back-end separation development is solved, simplification and cost reduction of mock testing are achieved, the operation steps are simplified and the implementation cost is reduced.

CN112131118BActive Publication Date: 2024-10-29PINGAN INT SMART CITY TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011024432.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-25
Publication Date
2024-10-29
Estimated Expiration
2040-09-25

AI Technical Summary

Technical Problem

In the process of separate front-end and back-end development, how the front-end performs Mock testing when the back-end interface is not completed is an urgent problem that needs to be solved. Existing methods such as building a Mock-Server or using packet capture software have high costs and cumbersome operations.

Method used

Intercept the interface address request by the interception server, call the script engine to obtain the interface information, and send it to the virtual interface server to generate response information to implement Mock testing, which simplifies the operation steps and reduces the implementation cost.

Benefits of technology

It achieves the simplification and cost reduction of Mock testing, avoids the need for supporting development interface proxy servers, and improves development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112131118B_ABST
    Figure CN112131118B_ABST
Patent Text Reader

Abstract

The present invention relates to a Mock test technology field, and provides a Mock test method, device, electronic device and computer-readable storage medium, wherein the method comprises: an interception server intercepts an interface address request sent by a request end, and obtains request address information contained in the interface address request; calls a script engine, and uses the script engine to obtain interface address information corresponding to the request address information; sends the interface address information to a virtual interface server and a virtual interface configuration management end, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates corresponding response information according to the virtual interface; receives the response information, and sends the response information to the request end, so that the request end uses the virtual interface to perform testing according to the response information. The present invention reduces the difficulty of Mock testing and reduces the implementation cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of Mock testing technology, and in particular to a Mock testing method, device, electronic equipment and computer-readable storage medium. Background Art

[0002] Currently, many developers separate the front-end and back-end during the development process so that the back-end interface can be supported for use by different terminals (such as web, iOS, and Android) to improve development efficiency. However, at the same time, there is a problem that the front-end UI depends on the back-end interface. Before the back-end interface is developed, how to simulate the back-end interface for testing has become an urgent problem to be solved.

[0003] The most commonly used methods are as follows:

[0004] The first method: build an independent Mock-Server (online interface simulation server), but this method requires the development of an interface proxy server, which has high implementation costs.

[0005] The second method is to use packet capture software to intercept network requests and replace the interface return value with data in the local file. However, this method has complicated operation steps, is not convenient for unified configuration, and has a high implementation cost. Summary of the invention

[0006] The present invention provides a Mock testing method, device, electronic device and computer-readable storage medium, the main purpose of which is to reduce the difficulty of Mock testing and reduce the implementation cost.

[0007] To achieve the above object, the present invention provides a Mock testing method, which comprises:

[0008] The interception server intercepts the interface address request sent by the requesting end, and obtains the request address information contained in the interface address request;

[0009] Calling a script engine, and using the script engine to obtain interface address information corresponding to the request address information;

[0010] Sending the interface address information to the virtual interface server and the virtual interface configuration management end, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates corresponding response information according to the virtual interface;

[0011] The response information is received, and the response information is sent to the requesting end, so that the requesting end performs a test using the virtual interface according to the response information.

[0012] Optionally, the calling of the script engine and obtaining the interface address information corresponding to the request address information by using the script engine comprises the following steps:

[0013] Calling the script engine, using the script engine to read the Mock interface mapping rules in the Mock configuration file, and

[0014] Determine whether the request address information matches the interface address information in the Mock interface mapping rule;

[0015] If the request address information matches the interface address information in the Mock interface mapping rule, the interface address information corresponding to the request address information is obtained.

[0016] Optionally, the determining whether the request address information matches the interface address information in the Mock interface mapping rule comprises the following steps:

[0017] Compare each line of information of the Mock interface mapping rule read with the request address information in the interface address request intercepted by the interception server;

[0018] It is determined according to the comparison result whether the request address information intercepted by the interception server matches the interface address information of the Mock interface mapping rule.

[0019] Optionally, the sending of the interface address information to a virtual interface server so that the virtual interface server provides a corresponding virtual interface according to the interface address information comprises the following steps:

[0020] The request address information is modified to virtual interface address information provided by the virtual interface server and corresponding to the interface address information.

[0021] Optionally, after the request address information is modified to virtual interface address information corresponding to the interface address information and provided by the virtual interface server,

[0022] The interception server obtains response information corresponding to the virtual interface configured by the virtual interface configuration management terminal.

[0023] Optionally, the response information includes an interface path, a protocol response code, a response delay, response header information, and a response content, wherein:

[0024] The interface path is used to configure the path matching information of the virtual interface;

[0025] The protocol response code is used to configure the protocol response code of the virtual interface;

[0026] The response delay is used to configure the time interval for the virtual interface to respond to the request of the requesting end after receiving the request;

[0027] The response header information is used to configure the response header information of the virtual interface;

[0028] The response content is used to configure the response content of the virtual interface.

[0029] Optionally,

[0030] If the request address information intercepted by the interception server does not match the interface address information of the Mock interface mapping rule, the interface address request initiated by the request end is released.

[0031] In order to solve the above problems, the present invention also provides a Mock testing device, the device comprising:

[0032] The interception request module is used to intercept the interface address request sent by the request end through the interception server, and obtain the request address information contained in the interface address request;

[0033] An interface address information acquisition module, used to call a script engine and use the script engine to acquire interface address information corresponding to the request address information;

[0034] A response information generating module, used for sending the interface address information to the virtual interface server and the virtual interface configuration management terminal, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management terminal generates corresponding response information according to the virtual interface;

[0035] The response information sending module is used to receive the response information and send the response information to the request end, so that the request end performs a test using the virtual interface according to the response information.

[0036] In order to solve the above problem, the present invention further provides an electronic device, the electronic device comprising:

[0037] at least one processor; and,

[0038] a memory communicatively connected to the at least one processor; wherein,

[0039] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned Mock testing method.

[0040] In order to solve the above problem, the present invention further provides a computer-readable storage medium, in which at least one instruction is stored. The at least one instruction is executed by a processor in an electronic device to implement the above-mentioned Mock testing method.

[0041] In the embodiment of the present invention, the interception server intercepts the interface address request sent by the request end, obtains the request address information contained in the interface address request; uses the script engine to obtain the interface address information corresponding to the request address information; sends the interface address information to the virtual interface server and the virtual interface configuration management end, so that the virtual interface server provides the corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates the corresponding response information according to the virtual interface; pushes the response information to the request end, so that the request end completes the Mock test. The present invention reads the Mock interface mapping rules in the Mock mapping configuration file through the interception server (Fiddler Proxy) and the script engine (Customize Rule), and matches and judges the request address information with the interface address information of the Mock interface mapping rule. The test process of the present invention is simple to implement and easy to operate, and the interception server itself has a proxy function, which can save the province to develop an interface proxy server, thereby effectively reducing the difficulty and cost of implementing the interface Mock test. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A schematic diagram of a Mock testing method according to an embodiment of the present invention;

[0043] Figure 2 A schematic diagram of a module of a Mock test device provided by an embodiment of the present invention;

[0044] Figure 3 A schematic diagram of the internal structure of an electronic device for implementing a Mock testing method provided by an embodiment of the present invention;

[0045] Figure 4 A schematic diagram of a tool used in a Mock testing method provided in an embodiment of the present invention.

[0046] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0047] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0048] The present invention provides a Mock testing method. Figure 1FIG. 1 is a flow chart of a Mock testing method provided by an embodiment of the present invention. The method can be executed by a device, and the device can be implemented by software and / or hardware.

[0049] In this embodiment, the Mock test method includes:

[0050] S1: The interception server intercepts the interface address request sent by the requesting end, and obtains the request address information contained in the interface address request;

[0051] S2: calling a script engine, and using the script engine to obtain interface address information corresponding to the request address information;

[0052] S3: sending the interface address information to the virtual interface server and the virtual interface configuration management end, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates corresponding response information according to the virtual interface;

[0053] S4: receiving the response information, and sending the response information to the requesting end, so that the requesting end performs a test using the virtual interface according to the response information.

[0054] The above is the specific process of the Mock test of the present invention. Figure 4 ,like Figure 4 As shown, in Figure 4 In the test process shown, the request end 42 sends an interface address request to the business API (Application Programming Interface, Chinese meaning: application program interface) service 41. When the Fiddler Proxy (interception server) 43 detects that the test preparation of the business API service is not completed, it intercepts the interface address request sent by the request end 42; Fiddler Proxy (interception server) 43 reads the Mock interface mapping rule in the Mock configuration file 45 through the Custom Rule (script engine) 44. If the intercepted request address information matches the interface address information of the Mock interface mapping rule, the intercepted request address information is forwarded to the corresponding Mock interface (virtual interface) provided by the MockServer (virtual interface server) 46; the Mock configuration management end (virtual interface configuration management end) 47 configures the response information of the Mock interface (virtual interface) provided by the Mock Server (virtual interface server) 46; through the Customize Rule (engine script) 44 and the Fiddler Proxy (interception server) 43, the response information is sent to the request end 42, thereby realizing the Mock test.

[0055] The following will Figure 1 Combination Figure 4 Detailed description of the Mock testing method process based on interception server and script engine.

[0056] In step S1, the interception server intercepts the interface address request sent by the request end and obtains the request address information contained in the interface address request. That is, the request end 42 initiates a request to the business API service 41 when the business API service 41 is not ready, and is intercepted by the Fiddler Proxy (interception server) 43.

[0057] Among them, the business API service 41 represents the service that actually provides the API interface for the request end 42 (such as the Web end) to call. Due to the use of the front-end and back-end separation development method, when the request end 42 is developed, the business API service 41 may not be completed. At this time, if you want to debug and test the request end 42, it is not feasible to directly call the business API server 41 to provide the interface for testing.

[0058] Although the logic of the business API service 41 has not been fully developed, according to the principle of separation of front-end and back-end, the interface definition of the business API service 41 has been completed at this time. Therefore, the business API service can be simulated by Mock testing (virtual testing) to achieve the purpose of debugging and testing the request end 42.

[0059] In an embodiment of the present invention, the request end 42 is the caller of the business API service, which may include different request ends such as: Web, Android, Ios, etc.; and the request end network proxy is set to an interception server (Fiddler Proxy), for example: configure the proxy to point to the interception server (Fiddler Proxy) in the mobile network connection proxy. That is to say, in an embodiment of the present invention, there is no need to develop an interface proxy service separately. By using the proxy function provided by the interception server (Fiddler Proxy), a simple configuration can be performed to realize the interface proxy calling function. That is: the request end calls the interface provided by the Mock Server (virtual interface server) through the Fiddler proxy (interception server) to obtain the simulated returned information data.

[0060] In step S2, the script engine is called, and the interface address information corresponding to the request address information is obtained by using the script engine. The calling of the script engine and the obtaining of the interface address information corresponding to the request address information by using the script engine include the following steps:

[0061] S21: calling the script engine, and using the script engine to read the Mock interface mapping rules in the Mock configuration file.

[0062] S22: Determine whether the request address information matches the interface address information in the Mock interface mapping rule. Specifically, the step of determining whether the request address information matches the interface address information in the Mock interface mapping rule comprises the following steps:

[0063] Compare each line of information of the Mock interface mapping rule read with the request address information in the interface address request intercepted by the interception server;

[0064] It is determined according to the comparison result whether the request address information intercepted by the interception server matches the interface address information of the Mock interface mapping rule.

[0065] S23: If the request address information matches the interface address information in the Mock interface mapping rule, then the interface address information corresponding to the request address information is obtained.

[0066] That is, if the request address information matches the interface address information in the Mock interface mapping rule, the request address is modified to a virtual interface address corresponding to the request address, wherein the virtual interface is provided by the virtual interface server according to the interface address information.

[0067] In addition, after determining whether the request address information matches the interface address information in the Mock interface mapping rule, the method further includes: if the request address information does not match the interface address information in the Mock interface mapping rule, the interface address request initiated by the request end is released.

[0068] In an embodiment of the present invention, the interception server 43 executes the script engine (Custom Rule) 44 to read the Mock interface mapping rules in the Mock configuration file 45, wherein the script engine (Custom Rule) reads the Mock interface mapping rules in the Mock configuration file until the Mock configuration file is read, and compares each line of information of the read Mock interface mapping rules with the request address information in the interface address request intercepted by the interception server to determine whether the request address information intercepted by the interception server matches the interface address information of this Mock interface mapping rule.

[0069] In the embodiment of the present invention, the Mock configuration file 45 is used to configure the mapping relationship between the mock interface (the request address information sent by the request end) and the post-mock interface (the Mock interface address information provided by the virtual interface server), wherein the mapping rules of the Mock configuration file are as follows:

[0070] The configuration item format in the Mock configuration file is: Mock interface path to be matched = post-Mock interface path; where the Mock interface path to be matched can be a full path match or a sub-path match, so the post-Mock interface path can be a full path or a suffix path after removing the server path.

[0071] In a specific embodiment of the present invention, an example is given in which an interception server uses Customize Rule (script engine) to obtain interface address information corresponding to the request address information, and obtains virtual interface address information corresponding to the interface address information according to the interface address information (virtual interface provided by a virtual interface server), thereby realizing the interface Mock function, wherein the specific process is as follows:

[0072] S210: Save the Mock configuration file to a preset path.

[0073] S220: Modify the interception server custom script file CustomRules.js and add customization in the OnBeforeRequest() method. The specific execution logic principle is as follows:

[0074] S221: Create a new object and open the Mock configuration file;

[0075] S222: Read the Mock interface mapping rules in the Mock configuration file line by line until the Mock configuration file is completely read;

[0076] S223: Compare each line of information of the read Mock interface mapping rule with the request address information intercepted by the interception server, and determine whether the request address information intercepted by the interception server matches the interface address information in the Mock interface mapping rule.

[0077] S224: If the request address information intercepted by the interception server in step S223 matches the Mock interface mapping rule, the request address intercepted by the interception server is modified to the Mock rear interface address.

[0078] S225: In step S223, if the request address information intercepted by the interception server does not match the interface address information of the Mock interface mapping rule, the request address intercepted by the interception server is not modified and is directly released.

[0079] For example: Assume that the Mock interface mapping rule read is:

[0080] / biz / bizapi1.do=http: / / mock-server / test / testapi1.do

[0081] When the request address information intercepted by the interception server is http: / / xxxx / biz / bizapi1.do, this request address information matches the interface address information of the Mock interface mapping rule.

[0082] Since the intercepted request address information matches the interface address information of the Mock interface mapping rule, the request address is modified to the post-Mock interface address (ie, the request address is modified to: http: / / mock-server / test / testapi1.do).

[0083] In step S3, the interface address information is sent to the virtual interface server and the virtual interface configuration management end, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates corresponding response information according to the virtual interface.

[0084] Specifically, in an embodiment of the present invention, if the request address information in the interface address request intercepted by the interception server matches the interface address information in the Mock interface mapping rule in the Mock configuration file, the interface address information is forwarded to the MockServer (virtual interface server) and the Mock configuration management terminal (virtual interface configuration management terminal) 47.

[0085] The step of sending the interface address information to the virtual interface server so that the virtual interface server provides a corresponding virtual interface according to the interface address information includes the following steps: modifying the request address information to virtual interface information corresponding to the interface address information provided by the virtual interface server.

[0086] In an embodiment of the present invention, after the request address information is modified to the virtual interface corresponding to the interface address provided by the virtual interface server, the interception server obtains the response information corresponding to the virtual interface configured by the virtual interface configuration management terminal. That is, the interception server configures the response information corresponding to the virtual interface according to the virtual interface configuration management terminal through the virtual interface configuration management terminal. The response information includes the interface path, the protocol response code (Http status code), the response delay, the response header information (Http Header) and the response content (HttpResponse).

[0087] That is to say, when the virtual interface of the Mock Server (virtual interface server) 46 receives the interface address request, the Mock Server (virtual interface server) 46 searches the database table (Mock interface information table) for the response information of the virtual interface corresponding to the interface address request according to the interface address request, and encapsulates the interface path, Http status code (response status code), response delay, Http Header (response header information) and Http Response (response content) in the query result into an Http response and returns it to the request end.

[0088] In an embodiment of the present invention, a Mock configuration management end (virtual interface configuration management end) is used to configure the response information of a Mock interface (virtual interface) according to the path information of the Mock interface (virtual interface), wherein the interface path is used to configure the path matching information of the Mock interface (virtual interface), which may be a full path match or a sub-path match; the Http status code is used to configure the HTTP protocol response code of the Mock interface (virtual interface); the response delay is used to configure how long the Mock interface delays responding to the client request after receiving the request; the Http Header is used to configure the Http response header information of the Mock interface (virtual interface); the Http Response is used to configure the Http response content of the Mock interface; and the response information (interface path, Http status code, response delay, Http Header, Http Response) is stored in the Mock interface information table.

[0089] In step S4, the response information is received, and the response information is sent to the requesting end, so that the requesting end performs a test using the virtual interface according to the response information.

[0090] Specifically, the Mock Server (virtual interface server) 46 encapsulates information such as the interface path, Http status code, response delay, Http Header and Http Response into response information, and the response information is returned to the request end through the script engine and the interception server, thereby completing the request end test.

[0091] In the embodiment of the present invention, the interception server intercepts the interface address request sent by the request end, obtains the request address information contained in the interface address request; uses the script engine to obtain the interface address information corresponding to the request address information; sends the interface address information to the virtual interface server and the virtual interface configuration management end, so that the virtual interface server provides the corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates the corresponding response information according to the virtual interface; pushes the response information to the request end, so that the request end completes the Mock test. The present invention reads the Mock interface mapping rules in the Mock mapping configuration file through the interception server (Fiddler Proxy) and the script engine (Customize Rule), and matches and judges the request address information with the interface address information of the Mock interface mapping rule. The test process of the present invention is simple to implement and easy to operate, and the interception server itself has a proxy function, which can save the province to develop an interface proxy server, thereby effectively reducing the difficulty and cost of implementing the interface Mock test.

[0092] like Figure 2 The figure shows a functional module diagram of the Mock testing device of the present invention.

[0093] The Mock test device 100 of the present invention can be installed in an electronic device. According to the functions implemented, the Mock test device based on the interception server and the script engine can include an interception request module 101, an interface address information acquisition module 102, a response information generation module 103, and a response information sending module 104. The module of the present invention can also be called a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.

[0094] In this embodiment, the functions of each module / unit are as follows:

[0095] The interception request module 101 is used to intercept the interface address request sent by the request end through the interception server, and obtain the request address information contained in the interface address request;

[0096] The interface address information acquisition module 102 is used to call a script engine and use the script engine to acquire the interface address information corresponding to the request address information;

[0097] A response information generating module 103 is used to send the interface address information to the virtual interface server and the virtual interface configuration management terminal, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management terminal generates corresponding response information according to the virtual interface;

[0098] The response information sending module 104 is used to receive the response information and send the response information to the requesting end, so that the requesting end performs a test using the virtual interface according to the response information.

[0099] Among them, the interception request module 101 is used to intercept the interface address request issued by the request end through the interception server, and obtain the request address information contained in the interface address request, that is: the request end 42 initiates a request to the business API service 41 when the business API service 41 is not ready, and is intercepted by Fiddler Proxy (interception server) 43.

[0100] Among them, the business API service 41 represents the service that actually provides the API interface for the request end 42 (such as the Web end) to call. Due to the development method of front-end and back-end separation, when the development of the request end 42 is completed, the business API service 41 may not have been completed. At this time, if you want to debug and test the request end 42, it is not feasible to directly call the business API service 41. Although the logic of the business API service 41 has not been fully developed, according to the principle of separation of front-end and back-end, the interface definition of the business API service 41 has been completed at this time, so the Mock test (virtual test) method can be used to simulate the business API service to achieve the purpose of debugging and testing the request end 42.

[0101] In an embodiment of the present invention, the request end 42 is the caller of the business API service, which may include different request ends such as: Web, Android, Ios, etc.; and the request end network proxy is set to an interception server (Fiddler Proxy), for example: configure the proxy to point to the interception server (Fiddler Proxy) in the mobile network connection proxy. That is to say, in an embodiment of the present invention, there is no need to develop an interface proxy service separately. By using the proxy function provided by the interception server (Fiddler Proxy), a simple configuration can be performed to realize the interface proxy calling function. That is: the request end calls the interface provided by the Mock Server (virtual interface server) through the Fiddler proxy (interception server) to obtain the simulated returned information data.

[0102] The interface address information acquisition module 102 includes:

[0103] A mapping rule reading module is used to call the script engine and use the script engine to read the Mock interface mapping rules in the Mock configuration file;

[0104] A judgment module, used to judge whether the request address information matches the interface address information in the Mock interface mapping rule;

[0105] The address information matching module is used to obtain the interface address information corresponding to the request address information if the request address information matches the interface address information in the Mock interface mapping rule.

[0106] Wherein, the judgment module includes:

[0107] An address information comparison module is used to compare each line of information of the read Mock mapping rule with the request address information in the interface address request intercepted by the interception server;

[0108] The matching judgment module is used to judge whether the request address information intercepted by the interception server matches the interface address information of the Mock interface mapping rule according to the comparison result.

[0109] In an embodiment of the present invention, the interception server reads the Mock interface mapping rules in the Mock configuration file through a script engine (Custom Rule), wherein the script engine (Custom Rule) is called to read the Mock interface mapping rules in the Mock configuration file until the Mock configuration file is read, and each line of information of the Mock interface mapping rules read is compared with the request address information intercepted by the interception server to determine whether the request address information intercepted by the interception server matches the interface address information in the Mock interface mapping rule.

[0110] If the request address information matches the interface address information in the Mock interface mapping rule, the request address is modified to a virtual interface address corresponding to the request address, wherein the virtual interface is provided by the virtual interface server according to the interface address information.

[0111] Among them, after judging whether the request address information matches the interface address information in the Mock interface mapping rule, it also includes: if the request address information intercepted by the interception server does not match the interface address information in the Mock interface mapping rule in the Mock configuration file, the interface address request initiated by the request end is directly released, that is: the request address information initiated by the request end is not modified.

[0112] In an embodiment of the present invention, the Mock configuration file is used to configure the mapping relationship between the mock interface (the request address information sent by the request end) and the post-mock interface (the Mock interface address information provided by the virtual interface server), wherein the mapping rules of the Mock configuration file are as follows:

[0113] The configuration item format in the Mock configuration file is: Mock interface path to be matched = post-Mock interface path; where the Mock interface path to be matched can be a full path match or a sub-path match, so the post-Mock interface path can be a full path or a suffix path after removing the server path.

[0114] In a specific embodiment of the present invention, an example is given in which an interception server uses Customize Rule (script engine) to obtain interface address information corresponding to the request address information, and obtains virtual interface address information corresponding to the interface address information according to the interface address information (virtual interface provided by a virtual interface server), thereby realizing the interface Mock function, wherein the specific process is as follows:

[0115] S210: Save the Mock configuration file to a preset path.

[0116] S220: Modify the interception server custom script file CustomRules.js and add customization in the OnBeforeRequest() method. The specific execution logic principle is as follows:

[0117] S221: Create a new object and open the Mock configuration file;

[0118] S222: Read the Mock interface mapping rules in the Mock configuration file line by line until the Mock configuration file is completely read;

[0119] S223: Compare each line of information of the read Mock interface mapping rule with the request address information intercepted by the interception server, and determine whether the request address information intercepted by the interception server matches the interface address information in the Mock interface mapping rule.

[0120] S224: If the request address information intercepted by the interception server in step S223 matches the interface address information in the Mock interface mapping rule, the request address intercepted by the interception server is modified to the Mock rear interface address.

[0121] S225: If the request address information intercepted by the interception server in step S223 does not match the interface address information in the Mock interface mapping rule, the request address intercepted by the interception server is not modified.

[0122] For example: Assume that the Mock interface mapping rule read is:

[0123] / biz / bizapi1.do=http: / / mock-server / test / testapi1.do

[0124] When the request intercepted by the interception server is http: / / xxxx / biz / bizapi1.do, the request address information matches the interface address information of the Mock interface mapping rule.

[0125] Since the intercepted request address information matches the interface address information of the Mock interface mapping rule, the request address is modified to the post-Mock interface address (ie, the request address is modified to: http: / / mock-server / test / testapi1.do).

[0126] The response information generation module 103 is used to send the interface address information to the virtual interface server and the virtual interface configuration management terminal, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management terminal generates corresponding response information according to the virtual interface.

[0127] Specifically, in an embodiment of the present invention, if the request address information in the interface address request intercepted by the interception server matches the interface address information in the Mock interface mapping rule in the Mock configuration file, the interface address information is forwarded to the MockServer (virtual interface server) and the Mock configuration management terminal (virtual interface configuration management terminal) 47.

[0128] In an embodiment of the present invention, after the request address information is modified to the virtual interface corresponding to the interface address provided by the virtual interface server, the interception server obtains the response information corresponding to the virtual interface configured by the virtual interface configuration management terminal. That is, the interception server configures the response information corresponding to the virtual interface according to the virtual interface configuration management terminal through the virtual interface configuration management terminal. The response information includes the interface path, the protocol response code (Http status code), the response delay, the response header information (Http Header) and the response content (HttpResponse).

[0129] That is to say, when the Mock interface (virtual interface) of the Mock Server (virtual interface server) 46 receives the interface address request, the Mock Server (virtual interface server) 46 searches the database table (Mock interface information table) for the interface response configuration information corresponding to the interface address request according to the interface address request, and encapsulates the interface path, Http status code, response delay, Http Header and Http Response in the query result into an Http response and returns it to the request end.

[0130] In an embodiment of the present invention, the Mock configuration management end is used to configure the response information of the Mock interface according to the Mock interface path information, wherein the interface path is used to configure the path matching information of the Mock interface, which can be a full path match or a subpath match; the Http status code is used to configure the HTTP protocol response code of the Mock interface; the response delay is used to configure how long the Mock interface delays responding to the client request after receiving the request; the Http Header is used to configure the Http response header information of the Mock interface; the Http Response is used to configure the Http response content of the Mock interface; and the response information (interface path, Http status code, response delay, Http Header, Http Response) is stored in the Mock interface information table.

[0131] In the response information sending module 104, the response information is received and sent to the requesting end, so that the requesting end performs a test using the virtual interface according to the response information.

[0132] Specifically, the Mock Server (virtual interface server) 46 encapsulates information such as the interface path, Http status code, response delay, Http Header and Http Response into response information, and the response information is returned to the request end through the script engine and the interception server, thereby completing the request end test.

[0133] In the embodiment of the present invention, the interception server intercepts the interface address request sent by the request end, obtains the request address information contained in the interface address request; uses the script engine to obtain the interface address information corresponding to the request address information; sends the interface address information to the virtual interface server and the virtual interface configuration management end, so that the virtual interface server provides the corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates the corresponding response information according to the virtual interface; pushes the response information to the request end, so that the request end completes the Mock test. The present invention reads the Mock interface mapping rules in the Mock mapping configuration file through the interception server (Fiddler Proxy) and the script engine (CustomizeRule), and matches and judges the request address information with the interface address information of the Mock interface mapping rule. The test process of the present invention is simple to implement and easy to operate, and the interception server itself has a proxy function, which can save the province to develop an interface proxy server, thereby effectively reducing the difficulty and cost of implementing the interface Mock test.

[0134] like Figure 3 FIG. 1 is a schematic diagram of the structure of an electronic device for implementing the Mock testing method of the present invention.

[0135] The electronic device 1 may include a processor 10 , a memory 11 , and a bus, and may also include a computer program stored in the memory 11 and executable on the processor 10 , such as a Mock test program 12 .

[0136] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, mobile hard disk, multimedia card, card-type memory (for example: SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. The memory 11 may be an internal storage unit of the electronic device 1 in some embodiments, such as a mobile hard disk of the electronic device 1. The memory 11 may also be an external storage device of the electronic device 1 in other embodiments, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 1. Further, the memory 11 may also include both an internal storage unit of the electronic device 1 and an external storage device. The memory 11 may not only be used to store application software and various types of data installed in the electronic device 1, such as the code of the data audit program, etc., but also be used to temporarily store data that has been output or is to be output.

[0137] The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips, etc. The processor 10 is the control core (Control Unit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules (such as data auditing programs, etc.) stored in the memory 11, and calls data stored in the memory 11, so as to execute various functions of the electronic device 1 and process data.

[0138] The bus may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.

[0139] Figure 3 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 2 The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.

[0140] For example, although not shown, the electronic device 1 may also include a power source (such as a battery) for supplying power to each component. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include any components such as one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, etc. The electronic device 1 may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.

[0141] Furthermore, the electronic device 1 may also include a network interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device 1 and other electronic devices.

[0142] Optionally, the electronic device 1 may further include a user interface, which may be a display, an input unit (such as a keyboard), or a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device 1 and to display a visual user interface.

[0143] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.

[0144] The Mock test program 12 stored in the memory 11 in the electronic device 1 is a combination of multiple instructions. When running in the processor 10, it can achieve:

[0145] The interception server intercepts the interface address request sent by the requesting end, and obtains the request address information contained in the interface address request;

[0146] Calling a script engine, and using the script engine to obtain interface address information corresponding to the request address information;

[0147] Sending the interface address information to the virtual interface server and the virtual interface configuration management end, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates corresponding response information according to the virtual interface;

[0148] The response information is received, and the response information is sent to the requesting end, so that the requesting end performs a test using the virtual interface according to the response information.

[0149] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to Figure 1 The description of the relevant steps in the corresponding embodiments will not be repeated here.

[0150] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).

[0151] In an embodiment of the present invention, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, a Mock testing method based on an interception server and a script engine is implemented. The specific method is as follows:

[0152] The interception server intercepts the interface address request sent by the requesting end, and obtains the request address information contained in the interface address request;

[0153] Calling a script engine, and using the script engine to obtain interface address information corresponding to the request address information;

[0154] Sending the interface address information to the virtual interface server and the virtual interface configuration management end, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates corresponding response information according to the virtual interface;

[0155] The response information is received, and the response information is sent to the requesting end, so that the requesting end performs a test using the virtual interface according to the response information.

[0156] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.

[0157] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0158] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.

[0159] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0160] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.

[0161] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.

Claims

1. A Mock testing method, characterized in that: The method comprises: The interception server intercepts the interface address request sent by the requesting end, and obtains the request address information contained in the interface address request; Calling a script engine, and using the script engine to obtain interface address information corresponding to the request address information; Sending the interface address information to the virtual interface server and the virtual interface configuration management end, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management end generates corresponding response information according to the virtual interface; receiving the response information, and sending the response information to the requesting end, so that the requesting end performs a test using the virtual interface according to the response information; The calling of the script engine and obtaining the interface address information corresponding to the request address information by using the script engine include the following steps: Calling the script engine, using the script engine to read the Mock interface mapping rules in the Mock configuration file, and Determine whether the request address information matches the interface address information in the Mock interface mapping rule; If the request address information matches the interface address information in the Mock interface mapping rule, then obtaining the interface address information corresponding to the request address information; The step of determining whether the request address information matches the interface address information in the Mock interface mapping rule comprises the following steps: Compare each line of information of the Mock interface mapping rule read with the request address information in the interface address request intercepted by the interception server; Determine whether the request address information intercepted by the interception server matches the interface address information of the Mock interface mapping rule according to the comparison result; The step of sending the interface address information to the virtual interface server so that the virtual interface server provides a corresponding virtual interface according to the interface address information comprises the following steps: Modifying the request address information into virtual interface address information corresponding to the interface address information provided by the virtual interface server; After the request address information is modified to the virtual interface address information corresponding to the interface address information provided by the virtual interface server, The interception server obtains the response information corresponding to the virtual interface configured by the virtual interface configuration management terminal; The response information includes the interface path, protocol response code, response delay, response header information and response content, wherein: The interface path is used to configure the path matching information of the virtual interface; The protocol response code is used to configure the protocol response code of the virtual interface; The response delay is used to configure the time interval for the virtual interface to respond to the request of the requesting end after receiving the request; The response header information is used to configure the response header information of the virtual interface; The response content is used to configure the response content of the virtual interface.

2. The Mock testing method according to claim 1, characterized in that: After determining whether the request address information matches the interface address information in the Mock interface mapping rule, the method further includes: If the request address information intercepted by the interception server does not match the interface address information of the Mock interface mapping rule, the interface address request initiated by the request end is released.

3. A Mock testing device, characterized in that: The device comprises: The interception request module is used to intercept the interface address request sent by the request end through the interception server, and obtain the request address information contained in the interface address request; An interface address information acquisition module, used to call a script engine and use the script engine to acquire interface address information corresponding to the request address information; A response information generating module, used for sending the interface address information to the virtual interface server and the virtual interface configuration management terminal, so that the virtual interface server provides a corresponding virtual interface according to the interface address information, and the virtual interface configuration management terminal generates corresponding response information according to the virtual interface; A response information sending module, used for receiving the response information, and sending the response information to the requesting end, so that the requesting end performs a test using the virtual interface according to the response information; The calling of the script engine and obtaining the interface address information corresponding to the request address information by using the script engine include the following steps: Calling the script engine, using the script engine to read the Mock interface mapping rules in the Mock configuration file, and Determine whether the request address information matches the interface address information in the Mock interface mapping rule; If the request address information matches the interface address information in the Mock interface mapping rule, then obtaining the interface address information corresponding to the request address information; The step of determining whether the request address information matches the interface address information in the Mock interface mapping rule comprises the following steps: Compare each line of information of the Mock interface mapping rule read with the request address information in the interface address request intercepted by the interception server; Determine whether the request address information intercepted by the interception server matches the interface address information of the Mock interface mapping rule according to the comparison result; The step of sending the interface address information to the virtual interface server so that the virtual interface server provides a corresponding virtual interface according to the interface address information comprises the following steps: Modifying the request address information into virtual interface address information corresponding to the interface address information provided by the virtual interface server; After the request address information is modified to the virtual interface address information corresponding to the interface address information provided by the virtual interface server, The interception server obtains the response information corresponding to the virtual interface configured by the virtual interface configuration management terminal; The response information includes the interface path, protocol response code, response delay, response header information and response content, wherein: The interface path is used to configure the path matching information of the virtual interface; The protocol response code is used to configure the protocol response code of the virtual interface; The response delay is used to configure the time interval for the virtual interface to respond to the request of the requesting end after receiving the request; The response header information is used to configure the response header information of the virtual interface; The response content is used to configure the response content of the virtual interface.

4. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the Mock testing method as described in any one of claims 1 to 2.

5. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the Mock testing method according to any one of claims 1 to 2 is implemented.

Citation Information

Patent Citations

  • Method and device for calling virtual interface in real time on basis of database service

    CN107577590A

  • Test data acquisition method and device, storage medium and computer equipment

    CN110727587A